what do you mean 'put them together' and which mistakes are you referring to? is the code not doing what you expect it to do?
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
well ... if you copy paste the errors here, I can take a look at it, but at the moment, I 'm not able to try and run your code to reproduce them.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
in your first class: replace the
example.getTitle() => example variable (not just in this statement) in myBook
in your second class, since
II Print the titles of available from the first library
is comment, not actual code, either put // before it, or /* */ around it.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
well, you try to call the getTitle() from a variable example, but your variable on which you should call these methods is called myBook, not example
so, this:
System.out.println("Title (should be The Da Vinci Code): " + example.getTitle());
should be:
System.out.println("Title (should be The Da Vinci Code): " + myBook.getTitle());
also for the other methods, off course
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
quite normal, you state that your method rented will return a boolean, but you don't return anything.
in next posts, could you also paste the text of the error message you are getting?
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
where do you set the value for borrowed?
and don't PM people with your code, this forum is a place where you can show your code, as well as have your problems solved in 'plain sight', so that others can benefit of it as well.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
you are not getting the point.
you need to set the values in the method you've implemented for that.
replace
public void returned() {
}
public void rented(){
}
either by:
public void setRented(boolean rented){
this.rented = rented;
}
or by
public void setRented(){
if ( isRented())
this.rented = false;
else
this.rented = true;
}
and adjust the calls to the method if needed.
at this point, no matter what or when you call isRented(), it will always return true.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
well ..
when you are hungry, do you throw a sandwhich together yourself, or do you sit, wait and starve to death, until someone tells you that you can and are allowed to make one yourself, and show you how to do it?
when studying a programming language, there's way too much information too be taught in its whole, not to mention that every day new libraries and frameworks are released or upgraded with new functionality. it's a part of your job to check out new options.
I'll repost that piece of code again, with some comments, maybe you'll have it easier to understand.
/* as the method name tells us, this method will be used to set the value of rented.
* rented is a boolean, which can only have true or false, which I assume you knew
* already, so, now there are two 'rules' you can follow here:
* 1. set based on the new value. this would mean that, even if the current value is
* true, you can still set the value to true.
* 2. set based on the current value. for instance, set paused/playing on a mp3
* player. if the playing is true, it needs to be set to false (to show that the
* song is paused.)
*/
public void setRented(){
// since you don't pass a parameter, you'll need to verify the current
// value of the boolean, which you can do by checking the value that the setter
// of the boolean variable returns.
if ( isRented())
// if it is true, set to false
this.rented = false;
else
// if it was false, set to true.
this.rented = true;
}
of course, there are more ways to do this, but I just added this way as an example that there are several ways you can set the value and there are several different logics that can be behind it.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
do remember: setRented only changes the value of the rented variable, you're still not setting the value of borrowed
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
well, the errors are quite self explanatory.. cannot find symbol => might be you didn't write the code, or maybe you didn't import the class you're trying to use.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433