Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Need BookTracker Class

  1. #1
    Member
    Join Date
    Jul 2012
    Posts
    71
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Need BookTracker Class

    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());
        }
    }


  2. #2
    Junior Member awinston's Avatar
    Join Date
    Jul 2012
    Location
    United States
    Posts
    10
    My Mood
    Fine
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need BookTracker Class

    Are you perhaps reading Introduction to Object-Oriented Programming?

    I found this as well as your other 2 classes via google: http://www.google.com/url?sa=t&rct=j...vjGcbqNw5PERPw
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  3. #3
    Member
    Join Date
    Jul 2012
    Posts
    71
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Need BookTracker Class

    yeah it is intro to OOP thanks for the link bro.... this is just what i needed

Similar Threads

  1. Replies: 3
    Last Post: June 17th, 2012, 06:22 PM
  2. Replies: 7
    Last Post: July 21st, 2011, 02:29 PM
  3. Replies: 3
    Last Post: April 13th, 2011, 03:30 PM
  4. Help requested - testing a class with a tester class, no methods allowed.
    By miketeezie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2011, 10:40 PM
  5. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM