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: 3590865 • 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,

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

Constructor

upoadLibrarians

savePatrons

PatronManager

Constructor

uploadPatrons

savePatrons

Catalog

Constructor

uploadCatalog

saveCatalog

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

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,

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

Constructor

upoadLibrarians

savePatrons

PatronManager

Constructor

uploadPatrons

savePatrons

Catalog

Constructor

uploadCatalog

saveCatalog

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

Explanation / Answer

Book.java

package library;

public class Book {

// private member variables isbn(id), title (String), year (int), and

// publisher (String)

private String isbn;

private String title;

private int year;

private String publisher;

// Constructor with parameters

public Book(String isbn, String title, int year, String publisher) {

this.isbn = isbn;

this.title = title;

this.year = year;

this.publisher = publisher;

}

// public setter , getter and constructor with parameters to the class

public String getIsbn() {

return isbn;

}

public void setIsbn(String isbn) {

this.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;

}

// toString() method to get the data related to Book

public String toString() {

return getIsbn() + ", " + getTitle() + ", " + getYear() + ", "+getPublisher();

}

}

Patron.java

package library;

/*

* Patron Class

*/

public class Patron{

//private member variables Id, first name, last name, job, year of birth, password

private String id;

private String firstName;

private String lastName;

private String job;

private int yearOfBirth;

private String password;

//Constructor with parameters firstname, lastName and email

public Patron(String id, String firstName, String lastName, String job, int yearOfBirth, String password) {

this.id=id;

this.firstName=firstName;

this.lastName=lastName;

this.job=job;

this.yearOfBirth=yearOfBirth;

this.password=password;

}

public String getId() {

return id;

}

public void setId(String id) {

this.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 getYearOfBirth() {

return yearOfBirth;

}

public void setYearOfBirth(int yearOfBirth) {

this.yearOfBirth = yearOfBirth;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

// toString that can be used for getting Author information readable

public String toString(){

return id+", "+ getFirstName()+", "+getLastName()+", "+getJob()+", "+getYearOfBirth()+", "+getPassword();

}

}

Librarian.java

package library;

/*

* class Person

*/

public class Librarian {

//member variables id, firstName (String), lastName (String), password

private String id;

private String firstName;

private String lastName;

private String password;

//Constructor with parameters

public Librarian(String id, String firstName, String lastName, String password){

this.id=id;

this.firstName=firstName;

this.lastName=lastName;

this.password=password;

}

//public setter , getter

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 getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

//toString method to read information related to Person

public String toString(){

return ""+id+", "+firstName+", "+lastName;

}

}

LibrarianManager.java

package library;

/*

* class Librarian

*/

public class Librarian {

//member variables id, firstName (String), lastName (String), password

private String id;

private String firstName;

private String lastName;

private String password;

//Constructor with parameters

public Librarian(String id, String firstName, String lastName, String password){

this.id=id;

this.firstName=firstName;

this.lastName=lastName;

this.password=password;

}

//public setter , getter

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 getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

//toString method to read information related to Person

public String toString(){

return ""+id+", "+firstName+", "+lastName;

}

}

LibrarianManager.java

package library;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

public class LibrarianManager {

Scanner inputStream;

FileWriter writer;

Librarian librarian;

String line;

//constructor

public LibrarianManager(Scanner inputStream){

this.inputStream= inputStream;

try {

writer = new FileWriter("D:/NewLibrarian.txt", false);

} catch (IOException e) {

e.printStackTrace();

}

}

public void uploadLibrarians(){

//split the words

while(inputStream.hasNextLine()){

line = inputStream.nextLine();

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

//setting Patron details for the first row of the txt file

String id=values[0];

String firstName=values[1];

String lastName=values[2];

String password=values[3];

librarian =new Librarian(id, firstName, lastName, password);

saveLibrarians();

}

}

public void saveLibrarians(){

try {

writer.append(librarian.toString());

writer.append(' ');

writer.flush();

} catch (IOException e) {

e.printStackTrace();

}

}

}

PatronManager.java

package library;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

public class PatronManager {

Scanner inputStream;

FileWriter writer;

Patron patron;

public PatronManager(Scanner inputStream){

this.inputStream= inputStream;

try {

writer = new FileWriter("D:/NewPatron.txt", false);

} catch (IOException e) {

e.printStackTrace();

}

}

public void upoloadPatrons(){

String line;

while(inputStream.hasNextLine()){

line = inputStream.nextLine();

//split the words

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

//setting Patron details for the first row of the txt file

String id=values[0];

String firstName=values[1];

String lastName=values[2];

String job=values[3];

int yearOfBirth=Integer.parseInt(values[4].trim());

String password=values[5];

patron =new Patron(id, firstName, lastName, job, yearOfBirth, password);

savePatrons();

}

}

public void savePatrons(){

try {

writer.append(patron.toString());

writer.append(' ');

writer.flush();

} catch (IOException e) {

e.printStackTrace();

}

}

}

Catalog.java

package library;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

public class Catalog {

private Book book;

private String[] authors;

Scanner inputStream;

FileWriter writer;

//constructor

public Catalog(Scanner inputStream){

this.inputStream= inputStream;

try {

writer = new FileWriter("D:/NewCatalog.txt", false);

} catch (IOException e) {

e.printStackTrace();

}

}

public void uploadCatalog(){

String line;

while(inputStream.hasNextLine()){

line = inputStream.nextLine();

//split the words

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

//setting Catalog details for the first row of the txt file

String isbn=values[0];

String title=values[1];

int year=Integer.parseInt(values[2].trim());

String publisher=values[3];

Book book =new Book(isbn, title,year,publisher);

String[] authors=values[4].split(";");

this.book=book;

this.authors=authors;

saveCatalog();

}

}

public void saveCatalog(){

try {

writer.append(book.toString());

//splits the authors using delemiter ;

for (String author : authors) {

writer.append(author+"; ");

}

writer.append(' ');

writer.flush();

} catch (IOException e) {

e.printStackTrace();

}

}

}

Transaction.java

package library;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

public class Transaction {

//Variables Transaction id, patron id, book isbn, from-date, returned-date, librarian

String transactionId;

String patronId;

String isbn;

String fromDate;

String returnDate;

String librarianId;

Scanner inputStream;

FileWriter writer;

String line;

public Transaction(Scanner inputStream){

this.inputStream= inputStream;

try {

writer = new FileWriter("D:/NewTransaction.txt", false);

} catch (IOException e) {

e.printStackTrace();

}

}

public String getTransactionId() {

return transactionId;

}

public void setTransactionId(String transactionId) {

this.transactionId = transactionId;

}

public String getPatronId() {

return patronId;

}

public void setPatronId(String patronId) {

this.patronId = patronId;

}

public String getIsbn() {

return isbn;

}

public void setIsbn(String isbn) {

this.isbn = isbn;

}

public String getFromDate() {

return fromDate;

}

public void setFromDate(String fromDate) {

this.fromDate = fromDate;

}

public String getReturnDate() {

return returnDate;

}

public void setReturnDate(String returnDate) {

this.returnDate = returnDate;

}

public String getLibrarianId() {

return librarianId;

}

public void setLibrarian(String librarian) {

this.librarianId = librarian;

}

public void uploadTransactions(){

while(inputStream.hasNextLine()){

line = inputStream.nextLine();

//split the words

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

//setting Transaction details for the first row of the txt file

setTransactionId(values[0]);

setIsbn(values[1]);

setPatronId(values[2]);

setFromDate(values[3]);

setReturnDate(values[4]);

setLibrarian(values[5]);

saveTransactions();

}

}

public void saveTransactions(){

try {

writer.append(this.toString());

writer.append(' ');

writer.flush();

} catch (IOException e) {

e.printStackTrace();

}

}

public boolean equals(Transaction transaction) {

if(transaction.getTransactionId().equals(this.transactionId))

return true;

return false;

}

@Override

public String toString() {

return transactionId+", "+isbn+", "+patronId+", "+fromDate+", "+returnDate+ ", "+librarianId;

}

}

LibraryTest.java---Main class

package library;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class LibraryTest {

public static void main(String[] args) {

//File paths of the each file

File catalogFile = new File("D:\workspace\Test\src\library\catalog.txt");

File patronFile = new File("D:\workspace\Test\src\library\patron.txt");

File LibrarianFile = new File("D:\workspace\Test\src\library\Librarian.txt");

File TransactionFile = new File("D:\workspace\Test\src\library\Transactions.txt");

try {

//scanners would scan the input file and passes the stream to constructor of respective class

Scanner catalogStream = new Scanner(catalogFile);

Catalog catalog=new Catalog(catalogStream);

catalog.uploadCatalog();

Scanner patronStream = new Scanner(patronFile);

PatronManager patron=new PatronManager(patronStream);

patron.upoloadPatrons();

Scanner librarianStream = new Scanner(LibrarianFile);

LibrarianManager library=new LibrarianManager(librarianStream);

library.uploadLibrarians();

Scanner transactionStream = new Scanner(TransactionFile);

Transaction transaction=new Transaction(transactionStream);

transaction.uploadTransactions();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

InputFiles:

catalog.txt

C-123, Java First, 2010, Wiley, James Fandy; Fond Bond
C-124,C# programming, 2016, Al Maaref, Nawwar Abu Ali; Samia Jamal; Nabeel Tawfeeq

Librarian.txt

L-123, Saleem, Salim, e1123
L-122, Faleh, Falah, et5555

patron.txt

P-2123, Ali , Salim, student, 2000, ali_salim
P-4442,Jameel, Jamal, employee, 1990, password
P-5555, Nasir, Boktief, faculty, 1980, my_password

Transactions.txt

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

OutputFiles:

NewCatalog.txt:

C-123, Java First, 2010, Wiley James Fandy; Fond Bond;
C-124, C# programming, 2016, Al Maaref Nawwar Abu Ali; Samia Jamal; Nabeel Tawfeeq;

NewPatron.txt:

P-2123, Ali , Salim, student, 2000, ali_salim
P-4442, Jameel, Jamal, employee, 1990, password
P-5555, Nasir, Boktief, faculty, 1980, my_password

NewLibrarian.txt

L-123, Saleem, Salim
L-122, Faleh, Falah

NewTransaction.txt:

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