Question & Answer: Book Cataloging System Write a program to manage a Book Catalog. The catalog would contain a collection of boo…..

Book Cataloging System Write a program to manage a Book Catalog. The catalog would contain a collection of books, with following fields of information: book code (unique for each book; must be valid - see ISBN validation rules in this assignment for more info), authors last name, authors first name, book title, year of publication and price. The book catalog should use a file for storing books The information in the file uses tabs to separate each of the field of a book, with one book per line. Refer to sample file: booklist.txt for more details. Usage Requireinents: 1. At the start, the program should load the catalog from file (Books.txt from current directory), if it doesnt exist, create a new catalog 2. The program should allow the user to add a new book to the catalog. The program should ask for the required information and then add the book to the catalog, only if same book code doesnt alreadv exist in the catalog and if the book is a valid. Book is considered valid, if the book code is valid, name and title are valid (name cant start with numbers, name/title cant be empty, price is not negative or zero, year cannot be greater than 2013) 3. The program should allow user to find a book in the catalog, given one of the following: author first name or last name or the book code. If the book is found, all the information about the book should be displayed. If the book is not found, an appropriate message should be displayed 4. The program should allow user to delete an existing book from the catalog. 5. The driver (or client) program should have a menu driven interface (console) to allow users to select one of the options to perform the above tasks and repeat them till the program is exited. The program should display appropriate messages to the user for each operation, successful or not 6. When exiting, the program should ask to save Yes/No the book catalog to file, taking in to account any of the above changes, for future reuseQuestion & Answer: Book Cataloging System Write a program to manage a Book Catalog. The catalog would contain a collection of boo..... 1Question & Answer: Book Cataloging System Write a program to manage a Book Catalog. The catalog would contain a collection of boo..... 2Question & Answer: Book Cataloging System Write a program to manage a Book Catalog. The catalog would contain a collection of boo..... 3

Book Cataloging System Write a program to manage a Book Catalog. The catalog would contain a collection of books, with following fields of information: book code (unique for each book; must be valid – see ISBN validation rules in this assignment for more info), author’s last name, author’s first name, book title, year of publication and price. The book catalog should use a file for storing books The information in the file uses tabs to separate each of the field of a book, with one book per line. Refer to sample file: booklist.txt for more details. Usage Requireinents: 1. At the start, the program should load the catalog from file (Books.txt from current directory), if it doesn’t exist, create a new catalog 2. The program should allow the user to add a new book to the catalog. The program should ask for the required information and then add the book to the catalog, only if same book code doesn’t alreadv exist in the catalog and if the book is a valid. Book is considered valid, if the book code is valid, name and title are valid (name can’t start with numbers, name/title can’t be empty, price is not negative or zero, year cannot be greater than 2013) 3. The program should allow user to find a book in the catalog, given one of the following: author first name or last name or the book code. If the book is found, all the information about the book should be displayed. If the book is not found, an appropriate message should be displayed 4. The program should allow user to delete an existing book from the catalog. 5. The driver (or client) program should have a menu driven interface (console) to allow users to select one of the options to perform the above tasks and repeat them till the program is exited. The program should display appropriate messages to the user for each operation, successful or not 6. When exiting, the program should ask to save Yes/No the book catalog to file, taking in to account any of the above changes, for future reuse

Expert Answer

 

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Book Cataloging System Write a program to manage a Book Catalog. The catalog would contain a collection of boo…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

The code is given below:

Library.java

import java.util.Scanner;

public class Library

{

private String libraryName;

private Borrower[] libraryUsers = new Borrower[20];

private BookInformation [] libraryItems = new BookInformation[2];

Scanner input = new Scanner(System.in);

int x=0;

int i=0;

public Library(String libraryName)

{

this.libraryName=libraryName;

}

private String inputString(String prompt) {

System.out.println(prompt);

return input.next();

}

private int inputInt(String prompt) {

int val = -1;

for(;;)/>

{

System.out.println(prompt);

try {

val = Integer.parseInt(input.next());

break;

}

catch (Exception ex) {

System.out.println(“Invalid value, please try again.”);

}

}

return val;

}

private double inputDouble(String prompt) {

double val = -1.00;

for(;;)/>

{

System.out.println(prompt);

try {

val = Double.parseDouble(input.next());

break;

}

catch (Exception ex) {

System.out.println(“Invalid value, please try again.”);

}

}

return val;

}

public void addUser(int choice)

{

if(choice==1)

{

String firstName = inputString(“Please enter your first name “);

String lastName = inputString(“Please enter your last name “);

String title = inputString(“Please enter your title “);

String dateOfBirth = inputString(“Please enter your date of birth “);

String homeAddress = inputString(“Please enter your home address “);

String phoneNumber = inputString(“Please enter your phone number “);

int barCode = inputInt(“Please enter your library card barcode”);

String studentId = inputString(“Please enter your Student ID “);

StudentBorrower studentBor = new StudentBorrower(firstName, lastName, title, dateOfBirth, homeAddress, phoneNumber, barCode, studentId);

libraryUsers[x]=studentBor;

x++;

}

else if(choice==2)

{

String firstName = inputString(“Please enter your first name “);

String lastName = inputString(“Please enter your last name “);

String title = inputString(“Please enter your title “);

String dateOfBirth = inputString(“Please enter your date of birth “);

String homeAddress = inputString(“Please enter your home address “);

String phoneNumber = inputString(“Please enter your phone number “);

int barCode = inputInt(“Please enter your library card barcode”);

String studentId = inputString(“Please enter your Student ID “);

StaffBorrower staffBor = new StaffBorrower(firstName, lastName, title, dateOfBirth, homeAddress, phoneNumber, barCode, studentId);

libraryUsers[x]=staffBor;

x++;

}

}

public void addItem(int choice)

{

if(choice==1)

{

String title = inputString(“Please enter your item code “);

String author = inputString(“Please enter the items due date “);

String year = inputString(“Please enter your items title “);

String price = inputString(“Please enter your books title “);

//Cannot find symbol – constructor BookInformation(java.lang.String,java.lang.String,java.lang.String,java.lang.String)

BookInformation book = new BookInformation(title,author,year,price);

libraryItems[i] = book;

i++;

}

else if(choice==2)

{

String title = inputString(“Please enter your item code “);

String author = inputString(“Please enter the items due date “);

String pages = inputString(“Please enter your items title “);

String refNumber = inputString(“Please enter your journals title “);

Journal jnal = new Journal(title,author,pages,refNumber);

libraryItems[x] = dvd;

i++;

}

}

public void getBorrowers()

{

for(int x=0; x<libraryUsers.length; x++)

{

if (libraryUsers[x] == null)

{

break;

}

else

{

System.out.println(libraryUsers[x].toString());

}

}

}

public void getItems()

{

for(int x=0; x<libraryItems.length; x++)

{

System.out.println(libraryItems[x].toString());

}

}

public Person[] searchUsers()

{

System.out.println(“Please enter the surname of the user you wish to find”);

return null;

}

public BookInformation[] searchItems()

{

return null;

}

public int textMenu()

{

System.out.println(“WELCOME TO ” + libraryName + ” LIBRARY” + “n”);

System.out.println(“To add a User, press 1” + “n”);

System.out.println(“To add an Item, press 2” + “n”);

System.out.println(“To list the users of this library, press 3” + “n”);

System.out.println(“To list the items in this library, press 4” + “n”);

System.out.println(“To search for a user, press 5” + “n”);

System.out.println(“To search for an Item, press 6” + “n”);

System.out.println(“To exit the system, press 7” + “n”);

int choice = input.nextInt();

return choice;

}

}

Person.java

public abstract class Borrower extends Person{

protected BookInformation [] itemsBorrowed;

private double currentFine;

private int barCode;

public Borrower(String FirstName, String LastName,

String homeAddress){

super(FirstName, LastName, homeAddress);

this.stuNumber=stuNumber;

}

 

public BookInformation [] getItemsBorrowed()

{

return itemsBorrowed;

}

public double getCurrentFine()

{

return currentFine;

}

public int getBarCode()

{

return barCode;

}

public void incrementFine(double addFine)

{

currentFine = currentFine+addFine;

}

 

public void decrementFine(double reduceFine)

{

currentFine = currentFine-reduceFine;

}

 

public abstract void addItem(int choice);

 

public void removeItem(BookInformation[] item, int index)

{

for(int i =0; i <item.length; i ++)

{

item[index]= null;

}

}

 

public String toString()

{

String borDetails = super.toString() +

“Bar code: ” + barCode +”n” +

“Items borrowed: ” + itemsBorrowed +”n”;

return borDetails;

}

}

StudentBorrower.java

import java.util.Scanner;

public class StudentBorrower extends Borrower

{

private final int maxItems = 7;

private final double maxFine = 5.00;

private String studentId;

Scanner input = new Scanner(System.in);

int x=0;

int i=0;

public StudentBorrower(String FirstName, String LastName, String title,

String dateOfBirth, String homeAddress, String phoneNumber,

int barCode, String studentId){

super(FirstName, LastName, homeAddress

);

this.studentId=studentId;

}

public void setId(String studentId)

{

this.studentId=studentId;

}

public int getMaxItems()

{

return maxItems;

}

public double getMaxFine()

{

return maxFine;

}

public String getID()

{

return studentId;

}

public void addItem(int choice)

{

if(choice==1 || choice==2 && maxItems>7)

{

System.out.println(“The maximum number of items allowed is 7” + “n” + “You currently have ” + maxItems +

“out at the moment”);

}

else if(choice==1 || choice==2 && maxFine>5.00)

{

System.out.println(“The maximum fine allowed is 5.00” + “n” + “You currently have ” + maxFine +

“worth of fines”);

}

else if(choice==1 && maxItems<7 && maxFine<5.00)

{

System.out.println(“Please enter the title of the book you wish to take out “);

String title = input.next();

/*

Book book = new Book(itemCode, dueDate, homeLibrary, title, bookTitle, bookAuthor, bookPublisher, bookId);

itemsBorrowed[i] = book;

i++;*/

}

else if(choice==2 && maxItems<7 && maxFine<5.00)

{

/*

Dvd dvd = new Dvd(itemCode, dueDate, homeLibrary, title, dvdTitle, dvdDirector, dvdLength, dvdId);

itemsBorrowed[x] = dvd;

x++;*/

}

}

}

Borrower.java

public abstract class Borrower extends Person{

protected BookInformation [] itemsBorrowed;

private double currentFine;

private int barCode;

public Borrower(String FirstName, String LastName,

String homeAddress){

super(FirstName, LastName, homeAddress);

this.stuNumber=stuNumber;

}

 

public BookInformation [] getItemsBorrowed()

{

return itemsBorrowed;

}

public double getCurrentFine()

{

return currentFine;

}

public int getBarCode()

{

return barCode;

}

public void incrementFine(double addFine)

{

currentFine = currentFine+addFine;

}

 

public void decrementFine(double reduceFine)

{

currentFine = currentFine-reduceFine;

}

 

public abstract void addItem(int choice);

 

public void removeItem(BookInformation[] item, int index)

{

for(int i =0; i <item.length; i ++)

{

item[index]= null;

}

}

 

public String toString()

{

String borDetails = super.toString() +

“Bar code: ” + barCode +”n” +

“Items borrowed: ” + itemsBorrowed +”n”;

return borDetails;

}

}

Still stressed from student homework?
Get quality assistance from academic writers!