-
need help wif homework
*****LET ME MAKE THIS CLEAR! I DON'T NEED SOMEONE TO DO THE WHOLE PROGRAM FOR ME! I AM JUST GIVING YOU ALL THIS INFORMATION SO YOU WON'T BE CONFUSED ON WHAT THE PROGRAM IS ALL ABOUT... I JUST NEED SOMEONE TO CHECK THE BOOK CLASS CODE AND HELP ME WITH THE IFSTATEMENT IN THE PATRON CLASS! IT IS AT THE BOTTOM OF THIS LONG POST!
I am new to java and I need much help with my school assignment... Here is the problem... I must write a library program... here is the question
Patrons of a library can borrow up to three books. A patron, therefore, has a name and up to three books. A book has an author and a title. Design and implement two classes, Patron and Book, to represent these objects and the following behavior:
-The client can instantiate a book with a title and author
-The client can examine but not modify a book's title or author
-The client can ask a patron wthere it has borrowed a given book (identified by title).
-The client can tell a patron to return a given book (identified by title).
-The client can tell a patron to borrow a given book.
The Patron class should use a seperate instance variable for each book (a total of three).
Each of these variables is initially null. When a book is borrowed, the patron looks for a variable that is not null. If no such variable is found, the method returns false. If a null variable is found, it is reset to the new book and the method returns true. Similar considerations apply to other methods. Use the method aString.equals(aString) to compare two strings for equality. Be sure to include appropriate toString methods for your classes and test them with a tester program.
My teacher already wrote out a tester program for us... unfortunately... i don't have a copy of it to show..
this here is what i have come up for the Book class
public class Book
//Instance Variables
String author;
String title;
//Constructor method
public void Book(){
author =" ";
title = " ";
public void setName (String a, String t) // a being author and t being title
//set author and title
author = a;
title = t;
//other methods
public string getAuthor(){
//Get Author
return Author;
public sgring getTitle(){
//Get Title
return Title;
public string toString(){
//Construct and return a string rep of the Book
String str;
str = "Author: " + author + "\n" +
"Title: " + title();
return str;
}
}
That's what i got... i dun know if that is even correct... but i think it's on the right track ne?
This is my little guide line that me and the teacher made
Book
Instance Vars - author, title (string)
Constructor - Book(), Book(author, title)
Methods- getAuthor, getTitle, toString
_________________________________
i followed that little map... and that's what i have got
I need major help on the Patron Class...
this is the little guide map
Patron
instance vars - name, book1, book2, book3
Constructors - Patron(), Patron(name) <-- string in front
Methods- hasBorrowed(title) - checked out <----- if(getTitle != null)
returnBook(title) - check in if(____.equals(__))
borrowBook(title) - check out
toString
This is what i came up with before my brain literally shut off for the day
public class Patron
//Instance Variables
String name,book1, book2, book3;
//Constructors
public Patron (){
name = " ";
book1 = " ";
book2 = " ";
book3 = " ";
}
public void setName (string nm){
name = nm;}
// methods
**** if(book1.getTitle() != null){
if(t.equals(t))
return book1;
else{
book 1 = t;}
} else {t = book2.getTitle();}
pretty pathetic huh... i know the patron makes no sense at all... but yeah... i have a hunch...
i just recently stared at this problem for 5 intense minutes... and i have come up with this(for the if statement in Patron)
would it be like
public void getTitle(){
if (book1.getTitle() != null){
if(t.equals(t))
book1 = t ;}
else if (book2.getTitle() != null){
if(t.equals(t))
book2 = t ; }
else book3 = t;
}
bleh.. i dun know... SOMEONE HELP ME PLEAASE!
blah blah blah
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks