Results 1 to 11 of 11
Thread: Need Direction
- 06-15-2011, 04:53 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 18
- Rep Power
- 0
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.
- 06-15-2011, 10:12 PM #2
Member
- Join Date
- Feb 2011
- Posts
- 30
- Rep Power
- 0
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 :)
- 06-15-2011, 10:26 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 18
- Rep Power
- 0
Still a little unclear, what do you mean by create my domain model?
- 06-15-2011, 10:27 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 06-16-2011, 01:41 AM #5
Member
- Join Date
- Dec 2010
- Posts
- 18
- Rep Power
- 0
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"); } }
- 06-16-2011, 01:52 AM #6
Your canBorrow method says that it will return a boolean but it doesn't.
- 06-16-2011, 03:09 AM #7
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
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)
- 06-16-2011, 03:50 AM #8
Member
- Join Date
- Dec 2010
- Posts
- 18
- Rep Power
- 0
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); } }
- 06-16-2011, 03:58 AM #9
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
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.
- 06-16-2011, 04:34 AM #10
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 06-16-2011, 06:45 AM #11
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
-
I need a little direction for a dictionary app
By Alexis in forum AWT / SwingReplies: 5Last Post: 02-11-2011, 07:43 PM -
random direction
By i8java in forum Threads and SynchronizationReplies: 5Last Post: 04-26-2010, 10:37 PM -
Looking for direction...
By ewomack in forum New To JavaReplies: 4Last Post: 09-13-2009, 11:00 PM -
[SOLVED] Need direction...
By hotice1027 in forum New To JavaReplies: 5Last Post: 11-28-2008, 09:03 AM -
I need direction too. output control
By bornwithnoname in forum New To JavaReplies: 0Last Post: 11-23-2008, 03:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks