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

Create a system managing a mini library system. Every book corresponds to a reco

ID: 3775590 • Letter: C

Question

Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named "mylibrary.txt". Each record consists of 6 fields (Book ID, Title, Author, Possession, Checked out Date, Due Date) separated by comma: 1, Book1, Author1, Library, null, null 2, Book1, Author1, User1, 2014-10-22, 2014-11-21 3, Book2, Author2, User1, 2014-10-23, 2014-11-22 4, Book3, Author2, User2, 2014-10-23, 2014-11-22 5, Book4, Atuhor3, User2, 2014-09-22, 2014-10-22 No comma ", " in title or author name. This mini library keeps the record for each book in the library. Different books can share the book "Title". But the "Book ID" for each book is unique. One author may have multiple books. Eg. Both book2 and book3 are written by author1 Possession field is "Library" means this book is kept in library, such as book #001. Otherwise, this book is checked out by the corresponding user. E.g. book #3 is checked out by User1. A user is allowed to check out up to 3 books. The "Checked out Date" field specifies the time of the latest checked out date. The loan period for each book is 30 days. "The Due Data" filed specifies the time the book should be returned. This system should provide a menu with following functionalities that the bookkeeper can choose from at the top-level menu: Enter "r" to return a book Ask for book ID. Examine if this book exists. If no, print a message "No such book!" and then go to 4). Otherwise, 3) Ask for current date and check if it is a legal date. If illegal, output "illegal input date" and go to step 7); otherwise, 4). Check if current date has passed "Due Date". If no, go to step 6). Otherwise, 5) Output the current fine to this book. Assume user has already paid for fine if it exists. Update the possession and date fields of the corresponding record. After that, print message "book*** return successfully!" and then go to 7). Provide options "t" for "" or "b" for "Back to main menu". (If "", go to step 1))

Explanation / Answer

import java.utill.*;

public class Library

{

public static void main(String args[])

{

char ch;

int BookID; //Book ID for checking

Date date = new Date(); // Taking Date object

SimpleDateFormat df = new SimpleDateFormat("E yyyy-MM-dd "); // Date format

System.out.println("Enter 'r' to return a book "); // Asking user to return a book

Scanner sc = new Scanner(System.in);

ch = sc.next().charAt(0);

while (ch!='e') // Menu continues till user presses 'E'

{

switch(ch) // Swtich case to access different menu items

{

case 'r':

System.out.println("Please enter BookID:");

BookID = sc.nextInt();

BufferedReader fin = new BufferedReader(new FileInputStream("mylibrary.txt"));

String Line = null;

while(Line=fin.readLine()!=null) // Reading Lines from the files

{

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

if(BookID==line[0]) // Checking for the Book ID in the current line

{

System.out.println("Please Enter the Current Date : ");

String dte = sc.nextLine();

dte=df.parse(dte);

if(dte !=date)

System.out.println("illegal input date");

if(dte > Duedate)

{

System.out.println("Please pay the fine ");

}

else

{

System.out.println("Book Returned Successfully");

break;

}

else

line=="notfound"; // If the book is not found then making the object as not found

}

if(line==notfound)

System.out.println("No Such Book found");

case 't': // Enter t to try again

System.out.println("Try Again");

case 'b':

System.out.println("Back to Main Menu");

case 'e':

System.out.println("Exiting"); break;

}

System.out.println("Enter your choice:");

ch = sc.next().charAt(0);

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote