Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the library system, develop at least the following classes along with the be

ID: 3595780 • Letter: F

Question

For the library system, develop at least the following classes along with the behavior/attributes listed below. For the upload/save methods, develop methods to read the files (see details below) and save them back to files.

You can add other classes in case you see them necessary to accomplish the functionality of the project.

Class

Attributes

Methods

Book

Isbn (id), name/title, year, published, list of authors

Constructors, Getters, setters, equals, toString

Patron

Id, first name, last name, job, year of birth, password

Constructors, Getters, setters, equals, toString

Librarian

Id, first name , last name, password.

Constructors, getters, setters, equals, toString

LibrarianManager

List/array of librarian

Constructor

upoadLibrarians

savePatrons

findLibrarianById (TBD)

AddLibrarian(TBD)

PatronManager

List/array of patrons

Constructor

uploadPatrons

savePatrons

findPatronById(TBD)

findPatronsByName(TBD)

AddPatron(TBD)

Catalog

List/array of books

Constructor

uploadCatalog

saveCatalog

findBookByIsbn(TBD)

findBookByAuthor(TBD)

addBook(TBD)

UpdateBook(TBD)

Transaction

This is to record the fact that a patron has borrowed a book from date1 to date 2 and he has returned it.

Transaction id, patron id, book isbn, from-date, returned-date, librarian (who checked out the book).

Constructor

uploadTransactions,

saveTransactions,

getters, setters, equals, toString

TransactionManager(TBD)

List/Array of transactions

Borrow

Return

Reporting.

LibraryApplication (TBD)

LibrarianManager

PatronManager

Catalog

TBD

For the purpose of testing, you should have 3 text files to be uploaded, namely, catalog, patrons, and librarians as follow. (feel free to change the format).

Entity

File Format

Catalog

#book isbn, title, year, publisher, author 1, author 2; author 3;;;

C-123, Java First, 2010, Wiley, James Fandy; Fond Bond

C-124,C# programming, 2016, Al Maaref, Nawwar Abu Ali; Samia Jamal; Nabeel Tawfeeq

….

Patron

#id, first name, last name, job, year of birth, password

P-2123, Ali , Salim, student, 2000, ali_salim

P-4442,Jameel, Jamal, employee, 1990, password

P-5555, Nasir, Boktief, faculty, 1980, my_password

….

Librarian

#Id, first name , last name, password.

L-123, Saleem, Salim, e1123

L-122, Faleh, Falah, et5555

….

Transactions

#Transaction id, book isbn ,patron id, , from-date, returned-date, librarian

T-123, C-123,P-2123,10/10/2016,12/10/2016, L-123

T-122,C-124,P-2123,01/01/207, 10/01/2017,L-123

T-121,C-123,P-442,23/09/2017/03/10/2017,L-122

Class

Attributes

Methods

Book

Isbn (id), name/title, year, published, list of authors

Constructors, Getters, setters, equals, toString

Patron

Id, first name, last name, job, year of birth, password

Constructors, Getters, setters, equals, toString

Librarian

Id, first name , last name, password.

Constructors, getters, setters, equals, toString

LibrarianManager

List/array of librarian

Constructor

upoadLibrarians

savePatrons

findLibrarianById (TBD)

AddLibrarian(TBD)

PatronManager

List/array of patrons

Constructor

uploadPatrons

savePatrons

findPatronById(TBD)

findPatronsByName(TBD)

AddPatron(TBD)

Catalog

List/array of books

Constructor

uploadCatalog

saveCatalog

findBookByIsbn(TBD)

findBookByAuthor(TBD)

addBook(TBD)

UpdateBook(TBD)

Transaction

This is to record the fact that a patron has borrowed a book from date1 to date 2 and he has returned it.

Transaction id, patron id, book isbn, from-date, returned-date, librarian (who checked out the book).

Constructor

uploadTransactions,

saveTransactions,

getters, setters, equals, toString

TransactionManager(TBD)

List/Array of transactions

Borrow

Return

Reporting.

LibraryApplication (TBD)

LibrarianManager

PatronManager

Catalog

TBD

Explanation / Answer

This is a big question, it needs a lot of time to work on. Somehow Ive managed to code almost everything. As per the requirements, created 9 classes Book, Catelog, Librarian, LibrarianManager, Transaction, TransactionManager, Patron, PatronManager and LibraryApplication. All the required functions and attributes are defined in each classes, and tested using LibraryApplication class with 4 input files catalogs.txt , patrons.txt , librarians.txt and transactions.txt. The data is fetched from corresponding files , saved it as a list by corresponding Managers, As I got only very less time , I cannot put more comments in the code. But you can easily understand everything. Test yourself by running the code and calling corresponding functions.

//LibraryApplication.java file

import java.io.File;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.text.ParseException;

import library.Catalog;

import library.LibrarianManager;

import library.PatronManager;

public class LibraryApplication {

static LibrarianManager libmanager;

static PatronManager patronManager;

static TransactionManager transManager;

static Catalog catalog;

public static void main(String[] args) {

File catalogfile=new File("catalog.txt");

File patronsfile=new File("patrons.txt");

File libfile=new File("librarians.txt");

File transsfile=new File("transactions.txt");

libmanager=new LibrarianManager();

patronManager=new PatronManager();

transManager=new TransactionManager();

catalog=new Catalog();

try {

System.out.println("PatronManager uploading patron details from file");

patronManager.uploadPatrons(patronsfile); /**fetching data from the file*/

System.out.println("Details of patrons");

System.out.println(patronManager.toString()); /**Displaying data to the screen*/

System.out.println("Catalog uploading books details from file");

catalog.uploadCatalog(catalogfile); /**fetching data from the file*/

System.out.println("Details of available books");

System.out.println(catalog.toString());/**Displaying data to the screen*/

System.out.println("LibrarianManager uploading librarian details from file");

libmanager.uploadLibrarians(libfile); /**fetching data from the file*/

System.out.println("Details of librarians");

System.out.println(libmanager.toString());/**Displaying data to the screen*/

System.out.println("TransactionManager uploading transaction details");

transManager.uploadTransactions(transsfile); /**fetching data from the file*/

System.out.println("Details of all transactions");

System.out.println(transManager.toString());/**Displaying data to the screen*/

patronManager.savePatrons(patronsfile); /**saving the files after everything*/

catalog.saveCatalog(catalogfile);

libmanager.saveLibrarians(libfile);

transManager.saveTransactions(transsfile);

} catch (FileNotFoundException e) {

e.printStackTrace();

}catch(NumberFormatException ne){

System.err.println("Invalid data file");

} catch (IOException e) {

e.printStackTrace();

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

//Book.java file

import java.util.ArrayList;

public class Book {

String Isbn;

String title;

int year;

String publisher;

ArrayList<String> authors;

public Book() {

}

public Book(String Isbn,String title,int year,String publisher,ArrayList<String> authors){

this.Isbn=Isbn;

this.title=title;

this.year=year;

this.publisher=publisher;

this.authors=authors;

}

public String getIsbn() {

return Isbn;

}

public void setIsbn(String isbn) {

Isbn = isbn;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public String getPublisher() {

return publisher;

}

public void setPublisher(String publisher) {

this.publisher = publisher;

}

public ArrayList<String> getAuthors() {

return authors;

}

public void setAuthors(ArrayList<String> authors) {

this.authors = authors;

}

public boolean equals(Book obj){

if(this.Isbn==obj.Isbn){

return true;

}else{

return false;

}

}

public String toString(){

String str="Book ID: "+Isbn+" ";

str+="Title: "+title+" ";

str+="Year published: "+year+" ";

str+="Publisher: "+publisher+" ";

str+="Authors:";

int i=0;

for (String auth : authors) {

i++;

str+=" "+i+": "+auth;

}

return str;

}

}

//Catelog.java file

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Scanner;

public class Catalog {

ArrayList<Book> bookslist;

public Catalog() {

bookslist = new ArrayList<Book>();

}

public Catalog(ArrayList<Book> bookslist) {

this.bookslist = bookslist;

}

public void uploadCatalog(File filename) throws FileNotFoundException {

Scanner scanner=new Scanner(filename);

while(scanner.hasNextLine()){

String line=scanner.nextLine();

if(!line.startsWith("#")){ /**checking if its a comment**/

String[] attrs=line.split(","); /**splitting based on comma**/

ArrayList<String> authlist= new ArrayList<String>(Arrays.asList(attrs[4].split(";"))); /**the author column can be of multiple persons,divided with a semicolon , we're splitting it and making a list*/

/**creating a Book object

and initializing the values by invoking parameterized constructors*/

Book book=new Book(attrs[0],attrs[1],Integer.parseInt(attrs[2].trim()),attrs[3],authlist);

bookslist.add(book);/**adding to the list*/

}

}

}

public void saveCatalog(File filename) throws IOException {

String str="#book isbn, title, year, publisher, author 1, author 2; author 3;;;";

FileWriter fw=new FileWriter(filename);

fw.write(str);

for (Book book : bookslist) {

str=" "+book.getIsbn()+","+book.getTitle()+","+book.getYear()+","+book.getPublisher()+",";

for (String auth : book.getAuthors()) {

str+=auth+";";

}

fw.append(str);

}

fw.close();

}

public Book findBookByIsbn(int Isbn){

for(Book book:bookslist){

if(book.getIsbn().equals(Isbn)){

return book;

}

}

return null;

}

public ArrayList<Book> findBookByAuthor(String auth){

ArrayList<Book> list=null;

for(Book book:bookslist){

if(book.getAuthors().contains(auth)){

if(list==null){

list=new ArrayList<Book>();

}

list.add(book);

}

}

return null;

}

public void addBook(Book book){

bookslist.add(book);

}

public void updateBook(Book book){

/**not clear if I need to update a book or the booklist*/

}

@Override

public String toString() {

String str="";

for (Book p : bookslist) {

str+=p.toString()+" ";

}

return str;

}

}

//Librarian.java file

public class Librarian {

String Id;

String firstname;

String lastname;

String password;

public Librarian(String id, String firstname, String lastname, String password) {

this.Id = id;

this.firstname = firstname;

this.lastname = lastname;

this.password = password;

}

public Librarian() {

}

public String getId() {

return Id;

}

public void setId(String id) {

Id = id;

}

public String getFirstname() {

return firstname;

}

public void setFirstname(String firstname) {

this.firstname = firstname;

}

public String getLastname() {

return lastname;

}

public void setLastname(String lastname) {

this.lastname = lastname;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public boolean equals(Librarian obj){

if(this.Id==obj.getId()){

return true;

}else{

return false;

}

}

public String toString() {

String str="Librarian ID: "+Id+" ";

str+="Firstname: "+firstname+" ";

str+="Lastname: "+lastname+" ";

return str;

}

}

//LibrarianManager.java file

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Scanner;

public class LibrarianManager {

static ArrayList<Librarian> librarianlist;

public LibrarianManager(ArrayList<Librarian> librarianlist) {

this.librarianlist = librarianlist;

}

public LibrarianManager() {

librarianlist=new ArrayList<Librarian>();

}

public void uploadLibrarians(File filename) throws FileNotFoundException{

Scanner scanner=new Scanner(filename);

while(scanner.hasNextLine()){

String line=scanner.nextLine();

if(!line.startsWith("#")){

String[] attrs=line.split(",");

Librarian librarian=new Librarian(attrs[0],attrs[1],attrs[2],attrs[3]);

librarianlist.add(librarian);

}

}

}

public void saveLibrarians(File filename) throws IOException{

String str="#Id, first name , last name, password";

FileWriter fw=new FileWriter(filename);

fw.write(str);

for (Librarian lib : librarianlist) {

str=" "+lib.getId()+","+lib.getFirstname()+","+lib.getLastname()+","+lib.getPassword();

fw.append(str);

}

fw.close();

}

public static Librarian findLibrarianById(String id){

id=id.trim();

for (Librarian lib : librarianlist) {

if(lib.getId().equals(id)){

return lib;

}

}

return null;

}

public void addLibrarian(Librarian lib){

librarianlist.add(lib);

}

@Override

public String toString() {

String str="";

for (Librarian p : librarianlist) {

str+=p.toString()+" ";

}

return str;

}

}

//Patron.java file

public class Patron {

String Id;

String firstname;

String lastname;

String job;

int year_of_birth;

String password;

public Patron(String id,String firstname,String lastname,String job,int year_of_birth,String password) {

this.Id=id;

this.firstname=firstname;

this.lastname=lastname;

this.job=job;

this.year_of_birth=year_of_birth;

this.password=password;

}

public Patron() {

}

public String getId() {

return Id;

}

public void setId(String id) {

Id = id;

}

public String getFirstname() {

return firstname;

}

public void setFirstname(String firstname) {

this.firstname = firstname;

}

public String getLastname() {

return lastname;

}

public void setLastname(String lastname) {

this.lastname = lastname;

}

public String getJob() {

return job;

}

public void setJob(String job) {

this.job = job;

}

public int getYear_of_birth() {

return year_of_birth;

}

public void setYear_of_birth(int year_of_birth) {

this.year_of_birth = year_of_birth;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public boolean equals(Patron obj){

if(this.Id==obj.getId()){

return true;

}else{

return false;

}

}

public String toString(){

String str="Patron ID: "+Id+" ";

str+="Firstname: "+firstname+" ";

str+="Lastname: "+lastname+" ";

str+="Job: "+job+" ";

str+="Birth Year: "+year_of_birth+" ";

return str;

}

}

//PatronManager.java file

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Scanner;

public class PatronManager {

ArrayList<Patron> patronslist;

public PatronManager(ArrayList<Patron> patronslist) {

this.patronslist = patronslist;

}

public PatronManager() {

patronslist=new ArrayList<Patron>();

}

public void uploadPatrons(File filename) throws FileNotFoundException{

Scanner scanner=new Scanner(filename);

while(scanner.hasNextLine()){

String line=scanner.nextLine();

if(!line.startsWith("#")){ /**checking if its a comment**/

String[] attrs=line.split(","); /**splitting based on comma**/

Patron patron=new Patron(attrs[0],attrs[1],attrs[2],attrs[3],Integer.parseInt(attrs[4].trim()),attrs[5]); /**creating a Patron object

and initializing the values by invoking parameterized constructors*/

patronslist.add(patron);/**adding to the list*/

}

}

}

public void savePatrons(File filename) throws IOException{

String str="#id, first name, last name, job, year of birth, password";

FileWriter fw=new FileWriter(filename);

fw.write(str);

for (Patron pat : patronslist) {

str=" "+pat.getId()+","+pat.getFirstname()+","+pat.getLastname()+","+pat.getJob()+","+pat.getYear_of_birth()+","+pat.getPassword();

fw.append(str);

}

fw.close();

}

public Patron findPatronById(int id){

for (Patron pat : patronslist) {

if(pat.getId().equals(id)){

return pat;

}

}

return null;

}

public ArrayList<Patron>findPatronsByName(String name){

ArrayList<Patron> list=null;

for (Patron pat : patronslist) {

if(pat.getFirstname().equalsIgnoreCase(name)||pat.getLastname().equalsIgnoreCase(name)){

if(list==null){

list=new ArrayList<Patron>();

}

list.add(pat);

}

}

return list;

}

public void addPatron(Patron pat){

patronslist.add(pat);

}

@Override

public String toString() {

String str="";

for (Patron p : patronslist) {

str+=p.toString()+" ";

}

return str;

}

}

// Transaction.java file

import java.text.SimpleDateFormat;

import java.util.Date;

public class Transaction {

String transId;

String patronId;

String bookIsbn;

Date fromDate;

Date returnDate;

String librarian;

public Transaction(String transId, String patronId, String bookIsbn, Date fromDate,

Date returnDate, String librarian) {

this.transId = transId;

this.patronId = patronId;

this.bookIsbn = bookIsbn;

this.fromDate = fromDate;

this.returnDate = returnDate;

this.librarian = librarian;

}

public Transaction() {

}

public String getTransId() {

return transId;

}

public void setTransId(String transId) {

this.transId = transId;

}

public String getPatronId() {

return patronId;

}

public void setPatronId(String patronId) {

this.patronId = patronId;

}

public String getBookIsbn() {

return bookIsbn;

}

public void setBookIsbn(String bookIsbn) {

this.bookIsbn = bookIsbn;

}

public Date getFromDate() {

return fromDate;

}

public void setFromDate(Date fromDate) {

this.fromDate = fromDate;

}

public Date getReturnDate() {

return returnDate;

}

public void setReturnDate(Date returnDate) {

this.returnDate = returnDate;

}

public String getLibrarian() {

return librarian;

}

public void setLibrarian(String librarian) {

this.librarian = librarian;

}

/*public void uploadTransactions(){

}

public void saveTransactions(){

}*/

public boolean equals(Transaction obj){

if(this.transId==obj.getTransId()){

return true;

}

return false;

}

public String toString() {

SimpleDateFormat sdf=new SimpleDateFormat("mm/dd/yy");

String str="Transaction ID: "+transId+" ";

str+="Patron ID: "+patronId+" ";

str+="Book ID: "+bookIsbn+" ";

str+="From Date: "+sdf.format(fromDate)+" ";

str+="Return Date: "+sdf.format(returnDate)+" ";

str+="Librarian: "+LibrarianManager.findLibrarianById(librarian).getFirstname()+" ";

return str;

}

}

// TransactionManager.java file

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Date;

import java.util.Scanner;

import library.Transaction;

public class TransactionManager {

ArrayList<Transaction> transactionslist;

public TransactionManager() {

transactionslist=new ArrayList<Transaction>();

}

public TransactionManager(ArrayList<Transaction> list) {

transactionslist = list;

}

public void uploadTransactions(File filename) throws ParseException, FileNotFoundException {

SimpleDateFormat sdf=new SimpleDateFormat("mm/dd/yyyy");

Scanner scanner=new Scanner(filename);

while(scanner.hasNextLine()){

String line=scanner.nextLine();

if(!line.startsWith("#")){

String[] attrs=line.split(",");

String transId=attrs[0];

String bookIsbn=attrs[1];

String patronId=attrs[2];

Date fromDate=sdf.parse(attrs[3]);

Date returnDate=sdf.parse(attrs[4]);

String librarian=attrs[5];

Transaction transaction=new Transaction(transId, patronId, bookIsbn, fromDate, returnDate, librarian);

transactionslist.add(transaction);

}

}

}

public void saveTransactions(File filename) throws IOException {

SimpleDateFormat sdf=new SimpleDateFormat("mm/dd/yyyy");

String str="#Transaction id, book isbn ,patron id, , from-date, returned-date, librarian";

FileWriter fw=new FileWriter(filename);

fw.write(str);

for (Transaction tr : transactionslist) {

str=" "+tr.getTransId()+","+tr.getBookIsbn()+","+tr.getPatronId()+","+sdf.format(tr.getFromDate())+","+sdf.format(tr.getReturnDate())+","+tr.getLibrarian();

fw.append(str);

}

fw.close();

}

public void borrow(){

/*not clear of the purpose*/

}

public void Return(){

/*not clear of the purpose*/

}

@Override

public String toString() {

String str="";

for (Transaction p : transactionslist) {

str+=p.toString()+" ";

}

return str;

}

}

//Output

Cannot be included as number of characters exceeded