Appropriately coded for a second quarter Java Class Book Cataloging System Write
ID: 3866524 • Letter: A
Question
Appropriately coded for a second quarter Java Class
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 reuseExplanation / Answer
Hi,
I could not complete the project in given time (2 hours). Please understand the below caode and little efforts required to finish the complete work. Please fell free to comment if you have any doubta
Book.java :-
-----------------------------------
/*
* Course Name :
* Program Name : BookCatalog
* Programmer Name :
* Program Description : Manage Book Catalog
* Date :
*
*/
public class Book {
private String code ;
private String authorFName;
private String authorLName;
private String bookTitle;
private int yearOfPublication;
private double price;
//Mutator method to set the Book Code
public void setCode(String code){
this.code = code;
}
//Accessor method to get the Book Code
public String getCode(){
return this.code;
}
//Mutator method to set the Author First name
public void setAuthorFname(String lname){
this.authorFName = lname;
}
//Accessor method to get the Author First name
public String getAuthorFname(){
return this.authorFName;
}
//Mutator method to set the Author Last name
public void setAuthorLname(String lname){
this.authorLName = lname;
}
//Accessor method to get the Author Last name
public String getAuthorLname(){
return this.authorLName;
}
//Mutator method to set the Book Title
public void setBookTitle(String title){
this.bookTitle = title;
}
//Accessor method to get the Book Title
public String getBookTitle(){
return this.bookTitle;
}
//Mutator method to set the Year of publication
public void setPubYear(int year){
this.yearOfPublication = year;
}
//Accessor method to get the Year of publication
public int getPubYear(){
return this.yearOfPublication;
}
//Mutator method to set the Year of publication
public void setPrice(double price){
this.price = price;
}
//Accessor method to get the Year of publication
public double getPrice(){
return this.price;
}
}
BookCatalog.java :-
---------------------------------------
/*
* Course Name :
* Program Name : BookCatalog
* Programmer Name :
* Program Description : Manage Book Catalog
* Date :
* Description : Maintains Book Catalog / List
*/
public class BookCatalog {
//Linked list head node
private BookListNode head = null;
//Variable to track current books count
private int numBooks = 0;
//Method to add new book to Catalog
public void addBook(Book newBook){
if(head == null){
head = new BookListNode(newBook);
}
else{
BookListNode node = head;
while(true){
if(node.next == null){
BookListNode newNode = new BookListNode(newBook);
node.next = newNode;
numBooks++;
newNode = null;
node = null;
break;
}
else{
node = node.next;
}
}
}
}
//Method to remove Book from Catalog
public void deleteBook(Book book){
BookListNode node = head;
//If item found at first element/node
if(node.book.getCode().equalsIgnoreCase(book.getCode())){
head = node.next;
node = null;
return;
}
while(true){
//Book not found and reached end of list
if(node.next == null){
break;
}
else if (node.next.book.getCode().equalsIgnoreCase(book.getCode())){
node.next = node.next.next;
}
else{
node = node.next;
}
}
node = null;
}
//Find book by ISBN Code
public Book findByCode(String code){
Book book = null;
BookListNode node = head;
while(true){
if(node.book.getCode().equalsIgnoreCase(code)){
book = node.book;
break;
}
else if (node.next == null){
break;
}
else {
node = node.next;
}
}
node = null;
return book;
}
//Find book by Author First name
public Book findByFname(String fname){
Book book = null;
BookListNode node = head;
while(true){
if(node.book.getAuthorFname().equalsIgnoreCase(fname)){
book = node.book;
break;
}
else if (node.next == null){
break;
}
else {
node = node.next;
}
}
node = null;
return book;
}
//Find book by Author Last name
public Book findByLname(String lname){
Book book = null;
BookListNode node = head;
while(true){
if(node.book.getAuthorLname().equalsIgnoreCase(lname)){
book = node.book;
break;
}
else if (node.next == null){
break;
}
else {
node = node.next;
}
}
node = null;
return book;
}
}
BookCatalogClient.java :-
--------------------------------------------------
import java.util.Scanner;
public class BookCatalogClient {
BookCatalog catalog = new BookCatalog();
// Create a single shared Scanner for keyboard input
private static Scanner scanner = new Scanner( System.in );
public void addBook(){
System.out.println("Eneter Book Code");
String fname,lname,title;
int year;
double price;
// Read a code from the user.
String code = scanner.nextLine();
if(validateIsbn13(code)){
System.out.println("Eneter Author First name");
// Read a code from the user.
fname = scanner.nextLine();
if(fname != null || fname.replace(" ", "").length() == 0 || Character.isDigit(fname.charAt(0))){
System.out.println("Enter valid name ");
return;
}
System.out.println("Eneter Author last name");
// Read a code from the user.
lname = scanner.nextLine();
if(lname != null || lname.replace(" ", "").length() == 0 || Character.isDigit(lname.charAt(0))){
System.out.println("Enter valid name ");
return;
}
System.out.println("Eneter Book Title");
// Read a code from the user.
title = scanner.nextLine();
}
else{
System.out.println("Enter valid ISBN code");
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BookCatalogClient client = new BookCatalogClient();
}
public static boolean validateIsbn13( String isbn )
{
if ( isbn == null )
{
return false;
}
//First character should be digit
try{
int digit = Integer.parseInt( isbn.substring( 0, 1 ) );
}
catch (Exception e){
return false;
}
//Check no continuous '-'
for (int i = 0 ; i < isbn.length(); i++){
if(i == isbn.length()-1){
if(isbn.substring(i).equalsIgnoreCase("X")){
break;
}
else{
try{
int digit = Integer.parseInt( isbn.substring( i) );
}
catch(Exception e){
return false;
}
}
}
else{
if(isbn.substring(i,i+1).equalsIgnoreCase("-") && isbn.substring(i+1,i+2).equalsIgnoreCase("-")){
return false;
}
}
}
//remove any hyphens
isbn = isbn.replaceAll( "-", "" );
//must be a 13 digit ISBN
if ( isbn.length() != 13 )
{
return false;
}
try
{
int tot = 0;
for ( int i = 0; i < 12; i++ )
{
int digit = Integer.parseInt( isbn.substring( i, i + 1 ) );
tot += (i % 2 == 0) ? digit * 1 : digit * 3;
}
//checksum must be 0-9. If calculated as 10 then = 0
int checksum = 10 - (tot % 10);
if ( checksum == 10 )
{
checksum = 0;
}
return (checksum == Integer.parseInt( isbn.substring( 12 )) || (isbn.substring( 12 ).equals("X")) );
}
catch ( NumberFormatException nfe )
{
//to catch invalid ISBNs that have non-numeric characters in them
return false;
}
}
}
BookListNode.java :-
-----------------------------------------
/*
* Course Name :
* Program Name : BookCatalog
* Programmer Name :
* Program Description : Manage Book Catalog
* Date :
*
* Description : This class represents a node in Linked List
*/
public class BookListNode {
Book book;
BookListNode next;
public BookListNode(Book book) {
// TODO Auto-generated constructor stub
this.book = book;
//Set next to null
this.next = null;
}
//Method to set next node link
public void setNextNode(BookListNode node){
this.next = node;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.