Results 1 to 11 of 11

Thread: Need Direction

  1. #1
    johnjacob is offline Member
    Join Date
    Dec 2010
    Posts
    18
    Rep Power
    0

    Default Need Direction

    I am working on a project and I am not sure where to begin, I was given a scenario and need to print a library receipt. Here is the scenario.

    You are working at the checkout counter of a library and want to write a program that will print out information about the items a borrower has just checked out. The borrower can borrow at least the following items: best selling book, children's book, and videos. They can also try to checkout reference books, but should receive a message that says the reference materials are for use within the library. You are to print out a receipt for borrowers telling them the name of their type of book, and how many days they can borrow the item for. Children's books can be borrowed for 20 days, videos can be borrowed for 3 days, reference materials for 0 days, and best sellers for 10 days. After an item is borrowed it should be marked as unavailable. Every item has a title. Books and videos have a category and children's books have an additional descriptor called reading level. Each type of book should be an extension of a base class that has attributes for the title, the number of borrowing days, and whether the book is available.

    Should I be creating a class and then extending the class using inheritance? Im a little unclear on where to go with this one. I dont want it done for me I just need a little help getting started. Im a complete newb when it comes to java.

  2. #2
    codesmuggler is offline Member
    Join Date
    Feb 2011
    Posts
    30
    Rep Power
    0

    Default

    At first, you have to create your domain model. Then create Data Access Object to access this data. Finally, create GUI. I hope this solution will help :)

  3. #3
    johnjacob is offline Member
    Join Date
    Dec 2010
    Posts
    18
    Rep Power
    0

    Default

    Still a little unclear, what do you mean by create my domain model?

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I suggest you first write of a rough design, get a pen and paper and write out every class you will need and what attributes and methods they need, then start at the smaller classes and build your way up.

  5. #5
    johnjacob is offline Member
    Join Date
    Dec 2010
    Posts
    18
    Rep Power
    0

    Default

    Here is what I have so far, im getting an error that says missing return statement.

    Java Code:
    import java.util.*;
    import java.io.*;
    
    public class Books
    {
    	 String title;
    	 int checkoutDays;
    	 int bookAvailability;
    
    	public Books()
    	{
    	title="";
    	checkoutDays = 0;
    	bookAvailability = 0;
    
    	}
    
    	boolean canBorrow()
    	{
    		if (checkoutDays > 0)
    
    		System.out.println("Book Name" + title + "Days allowed: " + checkoutDays);
    
    		else if (checkoutDays == 0)
    
    
    		System.out.println("Book is unavailable");
    
    }
    
    }

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    Your canBorrow method says that it will return a boolean but it doesn't.

  7. #7
    yellowledbet is offline Senior Member
    Join Date
    Feb 2011
    Location
    Georgia, USA
    Posts
    122
    Rep Power
    0

    Default

    Another thing to consider is that all of your items(Such as videos and books) are going to share functionality. It probably makes sense to create a super class that encompasses all of the common functionality. Then create your subclasses that inherit this functionality. This should save you from writing a bunch of redundant code.

    Inheritance (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)

  8. #8
    johnjacob is offline Member
    Join Date
    Dec 2010
    Posts
    18
    Rep Power
    0

    Default

    Ok not sure if this is what you mean I still need to write a class tester. Am I completely off here?
    Java Code:
    import java.util.*;
    import java.io.*;
    
    public class Books
    {
    	 String title;
    	 int checkoutDays;
    	 int bookAvailability;
    	 String readingLevel, category;
    
    	public Books()
    	{
    	title="";
    	checkoutDays = 0;
    	bookAvailability = 0;
    	}
    
    	   boolean canBorrow()
    	{
    	return false;
    
    	}
    
     void displayreceipt()
    	{
    	System.out.println("Book is unavailable");
    	}
    
    }
    
    class ReferenceBook extends Books
    {
    
    	    ReferenceBook()
    	   {
    	      super();
    	      title= ("World Reference");
    	      checkoutDays=0;
    
    	   }
    
    	   boolean canBorrow()
    	   {
    	      return false;
    	   }
    
    	    void refMaterial()
    	   {
    	      System.out.println("Book is for use in library only");
       }
    }
    
    class BestSeller extends Books
    {
    String fiction;
    	    BestSeller()
    	   {
    	      super();
    	      title= ("Mystic River");
    	      checkoutDays=10;
    		  category= fiction;
    	   }
    
    	   boolean canBorrow()
    	   {
    	      return true;
    	   }
    
    	    void displayreceipt()
    	   {
    	      System.out.println("Book Name" + title + "Days allowed: " + checkoutDays);
      	 }
    }
    
    class ChildrensBooks extends Books
    {
    String easy, fiction;
    	    ChildrensBooks()
    	   {
    	      super();
    	      title= ("Animal Farm");
    	      checkoutDays=20;
    		  category= fiction;
    		 readingLevel= easy;
    	   }
    
    	   boolean canBorrow()
    	   {
    	      return true;
    	   }
    
    	    void displayreceipt()
    	   {
    	      System.out.println("Book Name" + title + "Days allowed: " + checkoutDays);
      	 }
    }
    
    class Videos extends Books
    {
    String learning;
    	    Videos()
    	   {
    	      super();
    	      title= ("");
    	      checkoutDays = 3;
    		  category= learning;
    	   }
    
    	   boolean canBorrow()
    	   {
    	      return true;
    	   }
    
    	    void displayreceipt()
    	   {
    	      System.out.println("Video Name" + title + "Days allowed: " + checkoutDays);
      	 }
    }

  9. #9
    yellowledbet is offline Senior Member
    Join Date
    Feb 2011
    Location
    Georgia, USA
    Posts
    122
    Rep Power
    0

    Default

    No you definitely have the idea. Take a little time before you do too much coding to plan out the hierarchy and to decide what methods/functionality you want in all of your classes. If the method is the same from the superclass to the the subclass there is no need to redefine it.

    Also, I would go one level higher in the hierarchy and define a class like Item because it doesn't make much sense for a movie to extend a book. Keep going through the tutorials, you are on the right track. Also, hopefully some of the more experienced members will chime in as they are old pros.

  10. #10
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Your code is getting closer, and I can only type so much from my phone, but soon I'll have access to a laptop where I can give more feed back. I suggest you dissect the blob of text that is the assignment. It tells you what classes you should have. The top of the hierarchy is the most abstract type. This abstraction should only contain information that is abstract(common items). This goes for instance variables and methods.

    First get a deep understanding of what this base class should have encapsulated.

  11. #11
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Your best bet is to make sure you have the idea flow drawn up on paper, without it you will be more likely to jump into a puddle that's more of a pond and drown. Metaphorically speaking of course, but when you know exactly what everything needs to do before trying to code it you won't have to spend nearly as much time changing and adding things to code you've already tested.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Similar Threads

  1. I need a little direction for a dictionary app
    By Alexis in forum AWT / Swing
    Replies: 5
    Last Post: 02-11-2011, 07:43 PM
  2. random direction
    By i8java in forum Threads and Synchronization
    Replies: 5
    Last Post: 04-26-2010, 10:37 PM
  3. Looking for direction...
    By ewomack in forum New To Java
    Replies: 4
    Last Post: 09-13-2009, 11:00 PM
  4. [SOLVED] Need direction...
    By hotice1027 in forum New To Java
    Replies: 5
    Last Post: 11-28-2008, 09:03 AM
  5. I need direction too. output control
    By bornwithnoname in forum New To Java
    Replies: 0
    Last Post: 11-23-2008, 03:57 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •