Skip to content
This repository was archived by the owner on Apr 20, 2019. It is now read-only.

final assessment submission #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions src/main/java/nyc/c4q/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package nyc.c4q;

public class Book {

private int id;
private String title;
private String author;
private String isbn;
private String isbn13;
private String publisher;
private int publishyear;
private boolean checkedout;
private int checkedoutby;
private int checkoutdateyear;
private int checkoutdatemonth;
private int checkoutdateday;
private int duedateyear;
private int duedatemonth;
private int duedateday;

public Book(int id, String title, String author, String isbn, String isbn13, String publisher, int publishyear) {
this.id = id;
this.title = title;
this.author = author;
this.isbn = isbn;
this.isbn13 = isbn13;
this.publisher = publisher;
this.publishyear = publishyear;
}

@Override
public String toString() {
return "id: " + this.id + "\n" + "title: " + this.title + "\n" + "author: " + this.author + "\n" + "isbn: " + this.isbn + "\n" + "isbn13: " + this.isbn13 + "\n" + "publisher: " + this.publisher + "\n" + "publication year: " + this.publishyear + "\n";
}

public Book(int id, String title, String author, String isbn, String isbn13, String publisher, int publishyear, boolean checkedout, int checkedoutby, int checkoutdateyear, int checkoutdatemonth, int checkoutdateday, int duedateyear, int duedatemonth, int duedateday) {
this.id = id;
this.title = title;
this.author = author;
this.isbn = isbn;
this.isbn13 = isbn13;
this.publisher = publisher;
this.publishyear = publishyear;
this.checkedout = checkedout;
this.checkedoutby = checkedoutby;
this.checkoutdateyear = checkoutdateyear;
this.checkoutdatemonth = checkoutdatemonth;
this.checkoutdateday = checkoutdateday;
this.duedateyear = duedateyear;
this.duedatemonth = duedatemonth;
this.duedateday = duedateday;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getIsbn() {
return isbn;
}

public void setIsbn(String isbn) {
this.isbn = isbn;
}

public String getIsbn13() {
return isbn13;
}

public void setIsbn13(String isbn13) {
this.isbn13 = isbn13;
}

public String getPublisher() {
return publisher;
}

public void setPublisher(String publisher) {
this.publisher = publisher;
}

public int getPublishyear() {
return publishyear;
}

public void setPublishyear(int publishyear) {
this.publishyear = publishyear;
}

public boolean getCheckedout() {
return checkedout;
}

public void setCheckedout(boolean checkedout) {
this.checkedout = checkedout;
}

public int getCheckedoutby() {
return checkedoutby;
}

public void setCheckedoutby(int checkedoutby) {
this.checkedoutby = checkedoutby;
}

public int getCheckoutdateyear() {
return checkoutdateyear;
}

public void setCheckoutdateyear(int checkoutdateyear) {
this.checkoutdateyear = checkoutdateyear;
}

public int getCheckoutdatemonth() {
return checkoutdatemonth;
}

public void setCheckoutdatemonth(int checkoutdatemonth) {
this.checkoutdatemonth = checkoutdatemonth;
}

public int getCheckoutdateday() {
return checkoutdateday;
}

public void setCheckoutdateday(int checkoutdateday) {
this.checkoutdateday = checkoutdateday;
}

public int getDuedateyear() {
return duedateyear;
}

public void setDuedateyear(int duedateyear) {
this.duedateyear = duedateyear;
}

public int getDuedatemonth() {
return duedatemonth;
}

public void setDuedatemonth(int duedatemonth) {
this.duedatemonth = duedatemonth;
}

public int getDuedateday() {
return duedateday;
}

public void setDuedateday(int duedateday) {
this.duedateday = duedateday;
}
}
56 changes: 56 additions & 0 deletions src/main/java/nyc/c4q/BookContract.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package nyc.c4q;

import android.provider.BaseColumns;

public class BookContract {

public static final String PRIMARY_KEY = " PRIMARY KEY";
public static final String INT_TYPE = " INTEGER";
public static final String TEXT_TYPE = " TEXT";
public static final String BOOLEAN_TYPE = " BOOLEAN";
public static final String COMMA_SEP = ",";

public static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + BookEntry.TABLE_NAME +
" (" +
BookEntry.COLUMN_ID + INT_TYPE + PRIMARY_KEY + COMMA_SEP +
BookEntry.COLUMN_TITLE + TEXT_TYPE + COMMA_SEP +
BookEntry.COLUMN_AUTHOR + TEXT_TYPE + COMMA_SEP +
BookEntry.COLUMN_ISBN + TEXT_TYPE + COMMA_SEP +
BookEntry.COLUMN_ISBN13 + TEXT_TYPE + COMMA_SEP +
BookEntry.COLUMN_PUBLISHER + TEXT_TYPE + COMMA_SEP +
BookEntry.COLUMN_PUBLISHYEAR + INT_TYPE + COMMA_SEP +
BookEntry.COLUMN_CHECKEDOUT + BOOLEAN_TYPE + COMMA_SEP +
BookEntry.COLUMN_CHECKEDOUTBY+ INT_TYPE + COMMA_SEP +
BookEntry.COLUMN_CHECKOUTDATEYEAR + INT_TYPE + COMMA_SEP +
BookEntry.COLUMN_CHECKOUTDATEMONTH + INT_TYPE + COMMA_SEP +
BookEntry.COLUMN_CHECKOUTDATEDAY + INT_TYPE + COMMA_SEP +
BookEntry.COLUMN_DUEDATEYEAR + INT_TYPE + COMMA_SEP +
BookEntry.COLUMN_DUEDATEMONTH + INT_TYPE + COMMA_SEP +
BookEntry.COLUMN_DUEDATEDAY + INT_TYPE + COMMA_SEP +
")";

public static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + BookEntry.TABLE_NAME;

public static abstract class BookEntry implements BaseColumns {
public static final String TABLE_NAME = "BOOKS";
public static final String COLUMN_ID = "ID";
public static final String COLUMN_TITLE = "TITLE";
public static final String COLUMN_AUTHOR = "AUTHOR";
public static final String COLUMN_ISBN = "ISBN";
public static final String COLUMN_ISBN13 = "ISBN13";
public static final String COLUMN_PUBLISHER = "PUBLISHER";
public static final String COLUMN_PUBLISHYEAR = "PUBLISHYEAR";
public static final String COLUMN_CHECKEDOUT = "CHECKEDOUT";
public static final String COLUMN_CHECKEDOUTBY = "CHECKEDOUTBY";
public static final String COLUMN_CHECKOUTDATEYEAR = "CHECKOUTDATEYEAR";
public static final String COLUMN_CHECKOUTDATEMONTH = "CHECKOUTDATEMONTH";
public static final String COLUMN_CHECKOUTDATEDAY = "CHECKOUTDATEDAY";
public static final String COLUMN_DUEDATEYEAR = "DUEDATEYEAR";
public static final String COLUMN_DUEDATEMONTH = "DUEDATEMONTH";
public static final String COLUMN_DUEDATEDAY = "DUEDATEDAY";


}
}
45 changes: 45 additions & 0 deletions src/main/java/nyc/c4q/DBAsyncTask1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package nyc.c4q;

import android.content.Context;
import android.os.AsyncTask;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class DBAsyncTask1 extends AsyncTask<String, Void, Void> {

public Context context;

@Override
protected Void doInBackground(String... strings) {
LibraryDBHelper helper = new LibraryDBHelper(context);

try {
JSONArray books = new JSONArray(strings[0]);
for (int i = 0; i < books.length(); i++) {
JSONObject book = books.getJSONObject(i);
int id = book.getInt("id");
String title = book.getString("title");
String author = book.getString("author");
String isbn = book.getString("isbn");
String isbn13 = book.getString("isbn13");
String publisher = book.getString("publisher");
int publisheryear = book.getInt("publishyear");
boolean checkedout = book.getBoolean("checkedout");
int checkedoutby = book.getInt("checkedoutby");
int checkoutdateyear = book.getInt("checkoutdateyear");
int checkoutdatemonth = book.getInt("checkoutdatemonth");
int checkoutdateday = book.getInt("checkoutdateday");
int duedateyear = book.getInt("duedateyear");
int duedatemonth = book.getInt("duedatemonth");
int duedateday = book.getInt("duedateday");
Book newBook = new Book(id, title, author, isbn, isbn13, publisher, publisheryear, checkedout, checkedoutby, checkoutdateyear, checkoutdatemonth, checkoutdateday, duedateyear, duedatemonth, duedateday);
helper.insertBook(newBook);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}
36 changes: 36 additions & 0 deletions src/main/java/nyc/c4q/DBAsyncTask2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package nyc.c4q;

import android.content.Context;
import android.os.AsyncTask;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class DBAsyncTask2 extends AsyncTask<String, Void, Void> {

public Context context;

@Override
protected Void doInBackground(String... strings) {
LibraryDBHelper helper = new LibraryDBHelper(context);
try {
JSONArray members = new JSONArray(strings[0]);
for (int i = 0; i < members.length(); i++) {
JSONObject member = members.getJSONObject(i);
int id = member.getInt("id");
String name = member.getString("name");
int dob_month = member.getInt("dob_month");
int dob_day = member.getInt("dob_day");
int dob_year = member.getInt("dob_year");
String city = member.getString("city");
String state = member.getString("state");
Member newMember = new Member(id, name, dob_month, dob_day, dob_year, city, state);
helper.insertMember(newMember);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}
Loading