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

A simple java program that track of who has checkout library books. Write a chec

ID: 3534057 • Letter: A

Question

A simple java program that track of who has checkout library books. Write a checkout class that stores a three digit patron id, a ten character string for books id, a long showing the time that the book was checked out. the class should provide output and input operations and also equal() function.

Write your class, using your class write a program that a librarian can use to enter a book checkout, remove a checkout when a book is returned, or prints out all the books on loan. check outs should be stored in a list. You have to use System.current TimeMillis() method to get the time value.

Program should read a list of checked books from a file at the start and write a list when program completes- output the same file. program should make sure that each patron can check out no more than 3 books and no book can be checkout by two patron at once.

The format for file is patron id, space, book id, space and time on 1 line per book.

Explanation / Answer

below is checkout class. hope this helpes you

---------------------------------------------------------------------

import java.awt.Desktop;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.DataInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileWriter;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.Scanner;



public class CheckOut {


ArrayList<Book> checkedBookList=new ArrayList<Book>();


Scanner scan=new Scanner(System.in);

String fileName;

public void readBookList(String fileName)

{

String dir="C:/Users/timacs/Desktop/eclipse_workspace/temp/";

try{

FileInputStream fstream = new FileInputStream(dir+fileName);

DataInputStream in = new DataInputStream(fstream);

BufferedReader br = new BufferedReader(new InputStreamReader(in));

String strLine;

strLine = br.readLine();

strLine = br.readLine();

while ((strLine = br.readLine()) != null) {

String[] tokens = strLine.split(" ");

Book b=new Book();

  

b.setPatronId(Integer.parseInt(tokens[0].trim()));

b.setBookId(tokens[1].trim());

b.setTime(System.currentTimeMillis());

checkedBookList.add(b);


}

System.out.println(checkedBookList.size());

in.close();

}catch (Exception e){

e.printStackTrace();

}

}

public void checkInBook()

{

Book b=new Book();

int pId;

String bId;

System.out.println("Enter 3 digit patron code");

pId=Integer.parseInt(scan.nextLine());

System.out.println("Enter 10 letter Book Description");

bId=scan.nextLine();

System.out.println(checkedBookList.size());

for(int i=0;i<checkedBookList.size();i++)

{

b=checkedBookList.get(i);

if(b.getBookId().equals(bId) && b.getPatronId()==pId)

{

checkedBookList.remove(i);

break;

}

}

}

public void checkOutBook()

{

Book b=new Book();

System.out.println("Enter 3 digit patron code");

b.setPatronId(Integer.parseInt(scan.nextLine()));

System.out.println("Enter 10 letter Book Description");

b.setBookId(scan.nextLine());

b.time=System.currentTimeMillis();

checkedBookList.add(b);

}

public static void openFile(String fileName) {

String dir="C:/Users/timacs/Desktop/eclipse_workspace/temp/";

try {

File textFile = new File(dir+fileName);

if (textFile.exists()) {

if (Desktop.isDesktopSupported()) {

Desktop.getDesktop().open(textFile);

} else {

System.out.println("Awt Desktop is not supported!");

}

} else {

System.out.println("File is not exists!");

}

System.out.println("Done");

} catch (Exception ex) {

ex.printStackTrace();

}

}

public void printBookList(String fileName)

{

String dir="C:/Users/timacs/Desktop/eclipse_workspace/temp/";

try {

File file = new File(dir+fileName);

FileWriter fstream = new FileWriter(dir+fileName);

BufferedWriter out = new BufferedWriter(fstream);

System.out.println("Here are the Books Checked Out");

out.write("PatronId BookId Time");

System.out.println("PatronId BookId Time");

out.newLine();

out.write("------------------------------------");

System.out.println("------------------------------------");

out.newLine();

for(int i=0;i<checkedBookList.size();i++)

{

Book b=new Book();

b=checkedBookList.get(i);

out.write(b.getPatronId()+" "+b.getBookId()+" "+b.getTime());

System.out.println(b.getPatronId()+" "+b.getBookId()+" "+b.getTime());

out.newLine();

}

out.close();

openFile(fileName);

} catch (Exception ex) {

ex.printStackTrace();

}

}

}

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