If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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;

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

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)

When posting code in the forum (especially long sections of code), you should use the code tags and format it nicely. The code tags will make sure that what you write is correctly formatted so we can all read it easily. To use them it's pretty similar to HTML. You surround the code with the tags [ CODE ] and [ /CODE ] (but without the spaces inside the square brackets).

Anyway, I had a look at the IF statement you wrote at the end. There are a number of things I can see that will cause problems.

Firstly, you start with if(book1.getTitle() != null). Well in the Patron class book1 is a String. String doesn't have a getTitle() method, so this won't compile. Are the books meant to be in the form of a Book class? If so then they shouldn't be strings!

Second is the statement if(t.equals(t)). I had a look through but I couldn't find any variable named 't'. Even if there is a variable named 't' somewhere you should rename it. Variable names should give information about what the variable is for, and 't' doesn't give any indication at all.

More importantly, you are testing 't' against itself. This will always evaluate to true (if the equals method is written correctly and fulfills its contract), because they're both the same object! So basically, what is 't' and why are you comparing it to itself?

my teacher gave us that code if(t.equals(t)) ... and she told us to use t as the name.... i defined t somewhere... here it is..

public void setName (String a, String t) // a being author and t being title
//set author and title
author = a;
title = t;

would

if(getTitle() != null) work then?

well... you'd have to compare the title given by the tester when you see to check if you have "borrowed" the book... to what was originally assigned when you borrowed it.. then how are you supposed to do that if you can't compare the two? Ionno.. maybe in the tester program she gave us.. there is another variable we are supposed to test it with... maybe with the book strings... harhar... ionno... bleh... thankz for helping but it didn't fully answer my question... i still dun know what to exactly do since it's all wrong.. -_-... is those the only thing that's wrong or what? is the whole thing just screwed up or will it be okay if i fix what you mentioned...