I'm a student working on developing an app that checks library books checked out by a person and computes a charge to their account based on the date returned and the due date. The textbook says I require a predefined BookTracker class but my IDE says it doesn't exist. I was wondering if anybody had the class or could give me some tips concerning it.... Here's my code so far (I'm still working on it so nothing's final but it all compiles except for my bookTracker object)
import java.io.*; import java.text.*; import java.util.*; class OverdueChecker { public static void main(String[] args) { //Create 20 LibraryBook objects BookTracker bookTracker = new BookTracker(); //Create three LibraryBookobjects and output them GregorianCalendar dueDate, returnDate; LibraryBook book1, book2, book3, book4, book5; returnDate = new GregorianCalendar(2004, Calendar.MARCH, 15); dueDate = new GregorianCalendar(2004, Calendar.MARCH, 14); book1 = new LibraryBook(dueDate); dueDate = new GregorianCalendar(2004, Calendar.FEBRUARY, 13); book2 = new LibraryBook(dueDate, 0.75); book2.setTitle("Intro to OOP with Java"); dueDate = new GregorianCalendar(2004, Calendar.JANUARY, 12); book3 = new LibraryBook(dueDate, 1.00, 100.00); book3.setTitle("Java For Smart Folks"); dueDate = new GregorianCalendar(2004, Calendar.JANUARY, 11); book4 = new LibraryBook(dueDate, 1.50, 230.00, "Me and Java"); //Check error condition System.out.println("Error: No books added. Return code - " + bookTracker.getCharge(returnDate)); System.out.println("Output for empty book list:\n" + bookTracker.getList()); //Add 20 books System.out.println("\nAdding 20 books...\n"); for(int i = 0; i < 20; i++){ dueDate = new GregorianCalendar(2004, Calendar.MARCH, i); book5 = new LibraryBook(dueDate); book5.setTitle("Book Number " + i); bookTracker.add(book5); } System.out.println("Total Charge: $" + bookTracker.getCharge(returnDate)); System.out.println(); System.out.println("List: \n" + bookTracker.getList()); System.out.println(book1.toString()); System.out.println(book2.toString()); System.out.println(book3.toString()); System.out.println(book4.toString()); } }
import java.util.*; import java.text.*; class LibraryBook { private static final double CHARGE_PER_DAY = 0.50; private static final double MAX_CHARGE = 50.00; private static final String DEFAULT_TITLE = "Title Unknown"; private GregorianCalendar dueDate; private String title; private double chargePerDay; private double maximumCharge; public LibraryBook(GregorianCalendar dueDate){ this(dueDate, CHARGE_PER_DAY); } public LibraryBook(GregorianCalendar dueDate, double chargePerDay){ this(dueDate, chargePerDay, MAX_CHARGE); } public LibraryBook(GregorianCalendar dueDate, double chargePerDay, double maximumCharge){ this(dueDate, chargePerDay, maximumCharge, DEFAULT_TITLE); } public LibraryBook(GregorianCalendar dueDate, double chargePerDay, double maximumCharge, String title){ setDueDate(dueDate); setChargePerDay(chargePerDay); setMaximumCharge(maximumCharge); setTitle(title); } public double getChargePerDay(){ return chargePerDay; } public GregorianCalendar getDueDate(){ return dueDate; } public double getMaxCharge(){ return maximumCharge; } public String getTitle(){ return title; } public void setChargePerDay(double charge){ chargePerDay = charge; } public void setDueDate(GregorianCalendar date){ dueDate = date; } public void setMaximumCharge(double charge){ maximumCharge = charge; } public void setTitle(String title){ this.title = title; } public String toString(){ String tab = "\t"; DecimalFormat df = new DecimalFormat("0.00"); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy"); return String.format("%-30s $%5.2f $%7.2f %4$tm/%4$td/%4$ty", getTitle(), getChargePerDay(), getMaxCharge(), dueDate.getTime()); } }