public class Book {
String title;
boolean borrowed;
public Book(String bookTitle) {
}
public void borrowed() {
}
public void returned() {
}
public boolean isBorrowed() {
}
public String getTitle() {
}
public static void main(String[] arguments) {
Book myBook = new Book("Da Vinci");
myBook.name = "The Da Vinci Code"
System.out.println("Title (should be The Da Vinci Code): " + example.getTitle()); 
System.out.println("Borrowed?  (should be false): " + example.isBorrowed()); 
example.rented();
System.out.println("Borrowed?  (should be true): " + example.isBorrowed());
example.returned();
System.out.println("Borrowed?  (should be false): " + example.isBorrowed());
}
}

//
package library;

public class Library {

public static void main(String[] args) {

Library firstLibrary = new Library("10 Main St.");
Library secondLibrary = new Library("228 Liberty St.");

firstLibrary.addBook(new Book("The Da Vinci Code")); 
firstLibrary.addBook(new Book("Le Petit Prince")); 
firstLibrary.addBook(new Book("A Tale of Two Cities")); 
firstLibrary.addBook(new Book("The Lord of the Rings"));


System.out.println("Library  hours:"); 
printOpeningHours();
System.out.println();
System.out.println("Library addresses:"); 
firstLibrary.printAddress(); 
secondLibrary.printAddress(); 
System.out.println();


System.out.println("Borrowing  The Lord of the Rings:"); 
firstLibrary.borrowBook("The Lord of the Rings"); 
firstLibrary.borrowBook("The Lord of the Rings"); 
secondLibrary.borrowBook("The  Lord of the Rings"); 
System.out.println();


System.out.println("Books available in the first library:"); 
firstLibrary.printAvailableBooks();
System.out.println();
System.out.println("Books available in the second library:");
secondLibrary.printAvailableBooks();
System.out.println();II Return The Lords of the Rings to the first library 
System.out.println("Returning The Lord of the Rings:"); 
firstlibrary.returnBook("The Lord of the Rings");
System.out.println();
II Print the titles of available from the first library 
System.out.println("Books available in the first library:"); 
firstlibrary.printAvailableBooks();
}
}

Outputs:

Book.java
Title (should be The Da Vinci Code): The Da Vinci Code
Rented? (should be false): false
Rented? (should be true): true
Rented? (should be false): false

Library.java
Library hours:
Libraries are open daily from 9am to 5pm.
Library addresses:
10 Main St.
228 Liberty St.
Borrowing The Lord of the Rings:
You successfully borrowed The Lord of the Rings
Sorry, this book is already borrowed.
Sorry, this book is not in our catalog.
Books available in the first library:
The Da Vinci Code
Le Petit Prince
A Tale of Two Cities
Books available in the second library:
No book in catalog
Returning The Lord of the Rings:
You successfully returned The Lord of the Rings
Books available in the first library:
The Da Vinci Code
Le Petit Prince
A Tale of Two Cities
The Lord of the Rings

Questions:
Is there a chance that I can put the two classes together, how?
What are my mistakes?

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?

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?

okey never mind the 1st question, so is there something wrong of my codes? im using netbeans and I got a lot of errors

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.

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.

Sorry for the late reply this is the errors for the first class:

public boolean isBorrowed() {
}
public String getTitle() {
}
public static void main(String[] arguments) {
Book myBook = new Book("Da Vinci");
myBook.name = "The Da Vinci Code"
System.out.println("Title (should be The Da Vinci Code): " + example.getTitle()); 
System.out.println("Borrowed?  (should be false): " + example.isBorrowed()); 
example.rented();
System.out.println("Borrowed?  (should be true): " + example.isBorrowed());
example.returned();
System.out.println("Borrowed?  (should be false): " + example.isBorrowed());
}
}

Im trying to understand what you mean about your second post but I just dont understand sorry im not really good with java.

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

Thank You sir, The only problem now is this part is an error:

public boolean isBorrowed() {
}
public String getTitle() {
}
public boolean rented(){
}

every time I delete or change this part(above), errors are coming out in this section:

public static void main(String[] arguments) {
Book myBook = new Book("The Da Vinci Code");
System.out.println("Title (should be The Da Vinci Code): " + myBook.getTitle()); 
System.out.println("Borrowed?  (should be false): " + myBook.isBorrowed()); 
myBook.rented();
System.out.println("Borrowed?  (should be true): " + myBook.isBorrowed());
myBook.returned();
System.out.println("Borrowed?  (should be false): " + myBook.isBorrowed());}

I Add public boolean rented because of the myBook.rented(); << it give an error

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?

Okey sir

package book;

public class Book {
String title;
boolean borrowed;
public Book(String bookTitle) {
}
public void borrowed() {
}
public void returned() {
}
public boolean isBorrowed(){ << [COLOR="Red"]Missing Return statement[/COLOR]
}
public String getTitle() { << [COLOR="red"]Missing Return statement[/COLOR]
}
public static void main(String[] arguments) {

Book myBook = new Book("The Da Vinci Code"); << [COLOR="red"]Symbols: variable name
                                            Location: variable myBook of type book.Book[/COLOR]

myBook.name = "The Da Vinci Code"; 
System.out.println("Title (should be The Da Vinci Code): " + myBook.getTitle()); 

System.out.println("Borrowed?  (should be false): " + myBook.isBorrowed()); 

myBook.rented();<< [COLOR="red"]Sysmbols: variable name; Location: variable mybook of type boo.Book[/COLOR]
System.out.println("Borrowed?  (should be true): " + myBook.isBorrowed());

myBook.returned();
System.out.println("Borrowed?  (should be false): " + myBook.isBorrowed());
}
}

really need help

package book;

public class Book {

private String title;
private boolean borrowed;

public Book(String bookTitle) {
}
public void rented(){
}
public void borrowed() {
}
public void returned() {
}
public boolean isBorrowed () {
return borrowed;
}
public String getTitle() {
return title;
}
public static void main(String[] arguments) {

Book myBook = new Book("The Da Vinci Code");
myBook.title = "The Da Vinci Code";
System.out.println("Title (should be The Da Vinci Code): " + myBook.getTitle());
System.out.println("rented? (should be false): " + myBook.isBorrowed());

myBook.rented();
System.out.println("rented? (should be true): " + myBook.isBorrowed());

myBook.returned();
System.out.println("rented? (should be false): " + myBook.isBorrowed());
}
}

Is there something wrong with my codes?
I can't come up with the correct output:

Book.java
Title (should be The Da Vinci Code): The Da Vinci Code
Rented? (should be false): false
Rented? (should be true): true
Rented? (should be false): false


This is my current and wrong output:
Title (should be The Da Vinci Code): The Da Vinci Code
rented? (should be false): false
rented? (should be true): false
rented? (should be false): false

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.

ok
This is what I did with my code, is there something wrong with it?

package book;
public class Book {
private String title;
boolean borrowed;
boolean rented = true;
public Book(String bookTitle) {
}
public void returned() {
}
public void rented(){
}
public boolean isBorrowed () {
return borrowed;
}
public boolean isRented(){
return rented;
}
public String getTitle() {
return title;
}
public static void main(String[] arguments) {

Book myBook = new Book("The Da Vinci Code");

myBook.title = "The Da Vinci Code";
System.out.println("Title (should be The Da Vinci Code): " + myBook.getTitle());
System.out.println("rented? (should be false): " + myBook.isBorrowed());

myBook.rented();
System.out.println("rented? (should be true): " + myBook.isRented());

myBook.returned();
System.out.println("rented? (should be false): " + myBook.isBorrowed());
}
}

Output:
Title (should be The Da Vinci Code): The Da Vinci Code
Rented? (should be false): false
Rented? (should be true): true
Rented? (should be false): false


Now my problem is the other class the library.java codes anyone help?

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.

Thank you sir, sorry for your the inconvenience and Im not really good at Java that's why I really need you advice's and corrections.
also I could not believe that in this part
public void setRented(){
if ( isRented())
this.rented = false;
else
this.rented = true;
we could use if/else statement my instructor never said that or even gave examples

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.

Thank you sir, sorry for your the inconvenience and Im not really good at Java that's why I really need you advice's and corrections.
also I could not believe that in this part

public void setRented(){
 if (isRented())
   this.rented = false;
else 
  this.rented = true;

we could use if/else statement my instructor never said that or even gave examples

-------------------

this is the code

public class Book {
private String title;
boolean borrowed;
boolean rented;
public Book(String bookTitle) {
}
public void setRented(){
if(isRented())
        this.rented = false;
else
        this.rented = true;
}
public boolean isBorrowed () {
return borrowed;
}
public boolean isRented(){
return rented;
}
public String getTitle() {
return title;
}
public static void main(String[] arguments) {

Book myBook = new Book("The Da Vinci Code");

myBook.title = "The Da Vinci Code";
System.out.println("Title (should be The Da Vinci Code): " + myBook.getTitle()); 
System.out.println("rented?  (should be false): " + myBook.isBorrowed());

myBook.setRented();
System.out.println("rented?  (should be true): " + myBook.isRented());

myBook.setRented();
System.out.println("rented?  (should be false): " + myBook.isBorrowed());
}
}

do remember: setRented only changes the value of the rented variable, you're still not setting the value of borrowed

public class Library {
public Library(String Libraries) {
}
private String Library;
public static void main(String[] args) {

Library firstLibrary = new Library("10 Main St.");
Library secondLibrary = new Library("228 Liberty St.");

//errors in this part, cannot find symbol
//Symbol: class book
//location: class library.library
firstLibrary.addBook(new Book("The Da Vinci Code")); <<<
firstLibrary.addBook(new Book("Le Petit Prince")); <<<
firstLibrary.addBook(new Book("A Tale of Two Cities")); <<<
firstLibrary.addBook(new Book("The Lord of the Rings"))<<<;

System.out.println("Library hours:");
System.out.println("\nLibraries are open daily from 9am to 5pm");

//errors in this part, cannot find symbol
//symbol:method printAddress(java.lang.String)
//location:variable firstLibrary of type library.Library
System.out.println("Library addresses:");
firstLibrary.printAddress("10 Main St.");<<<
secondLibrary.printAddress("228 Liberty St.");<<<
System.out.println();

System.out.println("Borrowing The Lord of the Rings:");
firstLibrary.borrowBook("The Lord of the Rings"); <<<
firstLibrary.borrowBook("The Lord of the Rings"); <<<
secondLibrary.borrowBook("The Lord of the Rings"); <<<
System.out.println();

//cannot find symbol
//symbol:method printAvailableBooks()
//location:variable firstLibrary of type library.Library

System.out.println("Books available in the first library:");
firstLibrary.printAvailableBooks();<<<
System.out.println();
System.out.println("Books available in the second library:");
secondLibrary.printAvailableBooks();<<<
System.out.println("II Return The Lords of the Rings to the first library");
System.out.println("Returning The Lord of the Rings:");

//cannot find symbol
/symbol:variable firstlibrary
//location:class library.Library
firstlibrary.returnBook("The Lord of the Rings");<<<
System.out.println("II Print the titles of available from the first library");
System.out.println("Books available in the first library:");
firstlibrary.printAvailableBooks();<<<
}}
NOTE: Codes with <<< have the errors listed above

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.

do remember: setRented only changes the value of the rented variable, you're still not setting the value of borrowed

but im getting the right output and no errors with the codes.

when I put this code:
public void setBorrowed(boolean isBorrowed){
this.borrowed = borrowed;}
netbeans says ("Assignment to itself") but I can still run the codes

that is, because your parameter is not called 'borrowed', it is named isBorrowed, so change that code to:

public void setBorrowed(boolean isBorrowed){
this.borrowed = isBorrowed;}

that is, because your parameter is not called 'borrowed', it is named isBorrowed, so change that code to:

public void setBorrowed(boolean isBorrowed){
this.borrowed = isBorrowed;}

Okey change it, I already did that code and its an error, my mistake because what I did is this
public void setBorrowed(boolean isBorrowed){
this.borrowed = isborrowed;} the small b and the big B I have to pay more attention with the letters

yup ... Java is extremely case sensitive, so isborrowed and isBorrowed will never be seen as the same variable names.

yup ... Java is extremely case sensitive, so isborrowed and isBorrowed will never be seen as the same variable names.

Can you help me with the other program, sir?

what other program?
if it's another problem / application entirely, start a new thread with the code and what it's doing wrong, if it's still a part of this program, ask your question here.

what other program?
if it's another problem / application entirely, start a new thread with the code and what it's doing wrong, if it's still a part of this program, ask your question here.

I guess I have to make another thread for library.java and mark this thread solve

SOLVED

package book;
public class Book {
public String title;
boolean borrowed;
boolean rented;
public Book(String bookTitle){
}
public void setRented(){
if(isRented())
        this.rented = false;
else
        this.rented = true;}
public void setBorrowed(boolean isBorrowed){
this.borrowed = isBorrowed;}
public boolean isBorrowed () {
return borrowed;}
public boolean isRented(){
return rented;}
public String getTitle() {
return title;}
public static void main(String[] arguments) {
Book myBook = new Book("The Da Vinci Code");
myBook.title = "The Da Vinci Code";
System.out.println("Title (should be The Da Vinci Code): " + myBook.getTitle()); 
System.out.println("rented?  (should be false): " + myBook.isBorrowed());
myBook.setRented();
System.out.println("rented?  (should be true): " + myBook.isRented());
myBook.setRented();
System.out.println("rented?  (should be false): " + myBook.isBorrowed());
}}

OUTPUT:
Title (should be The Da Vinci Code): The Da Vinci Code
rented? (should be false): false
rented? (should be true): true
rented? (should be false): false

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.