I tried to run this in netbeans but it had a lot of errors(constructor, methods, field, and etc....) i'm confuse where to start they said start implementing the missing codes but how our instructor is very confusing
Really need help anyone?
This is the skeleton:
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();
}}
This is the output of the program.
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
6 replies to this topic
#1
Posted 08 December 2011 - 03:58 AM
|
|
|
#2
Posted 08 December 2011 - 04:22 AM
There is little for us to say apart from: fix the errors one by one.
You don't have to write code in all the methods and constructors you need, just start by getting the project to compile and run.
eg. this line is probably red:
After that try figuring out what kind of stuff each method would need to do to get the desired results.
You don't have to write code in all the methods and constructors you need, just start by getting the project to compile and run.
eg. this line is probably red:
Library firstLibrary = new Library("10 Main St.");
So just addpublic Library(String address){
}
And leave that empty to begin with, do that for everything until you get something that compiles and runs.After that try figuring out what kind of stuff each method would need to do to get the desired results.
#3
Posted 08 December 2011 - 10:58 AM
Done with that, what I did next was this part first (code below) I made a constructor it pops up in a new tab now I don't know whats next. I think I have to make a method but I don't know how to make it. it wasnt explain well at class.
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"));
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"));
#4
Posted 08 December 2011 - 11:02 AM
public class Library {
String address;
String title;
int noOfBooks;
int date;
Book book = new Book("Book Name");
ArrayList<Book> myArr = new ArrayList<Book>();
String[] myAr = new String[noOfBooks];
//ArrayList<String> BookList = new ArrayList();
//ArrayList<Score> list = new ArrayList<Score>();
public Library(String LibAddress, Book bk) {
address = LibAddress;
book = bk;
}
public void printOpeningHours() {
//System.out.println("Library hours");
System.out.println("Libraries are open daily from 9am to 5pm.");
}
public String getAddress(){
return address;
}
public void printAddress() {
System.out.println(address);
}
public String getTitle () {
//if(title != null)
return title;
}
public void addBook(Book bookObject) {
if (bookObject != null && noOfBooks<4) {
book[noOfBooks] = bookObject;
//myAr[noOfBooks] = book[noOfBooks];
noOfBooks++; //increase after adding one book to the Library
}// end if
} // end addBook
#5
Posted 08 December 2011 - 10:25 PM
Now I hate JAVA:cursing:
#6
Posted 11 December 2011 - 11:04 PM
This is what I Did, Im I doing right???
I got some errors, help>>??!
I got some errors, help>>??!
public class Library {
private static class ArrayList<T> {
public ArrayList() {
}
}
public static class Book {
public Book() {
}
}
public Library(String address){
}
public Library(String LibAddress, Book bk) {
address = LibAddress;
book = bk;
}
String address;
String title;
int noOfBooks;
int date;
[COLOR="#FF0000"]Book book = new Book("Book Title"); [/COLOR]
ArrayList<Book> myArr = new ArrayList<Book>();
String[] myAr = new String[noOfBooks];
ArrayList<String> BookList = new ArrayList();
//ArrayList<Score> list = new ArrayList<Score>();
public static void printOpeningHours() {
System.out.println("Library hours");
System.out.println("Libraries are open daily from 9am to 5pm.");
}
public String getAddress(){
return address;
}
public void printAddress() {
System.out.println(address);
}
public String getTitle () {
//if(title != null)
return title;
}
public void addBook(Book bookObject) {
if (bookObject != null && noOfBooks<4) {
//book[noOfBooks] = bookObject;
//myAr[noOfBooks] = book[noOfBooks];
noOfBooks++; //increase after adding one book to the Library
}// end if
} // end add
public static void main(String[] args) {
Library firstLibrary = new Library("10 Main St.");
Library secondLibrary = new Library("228 Liberty St.");
[COLOR="#FF0000"]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"));[/COLOR]
printOpeningHours();
System.out.println("Library addresses:");
firstLibrary.printAddress();
secondLibrary.printAddress();
System.out.println();
System.out.println("Borrowing The Lord of the Rings:");
[COLOR="#FF0000"]firstLibrary.borrowBook("The Lord of the Rings");
firstLibrary.borrowBook("The Lord of the Rings");
secondLibrary.borrowBook("The Lord of the Rings"); [/COLOR]
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:");
[COLOR="#FF0000"]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 [/COLOR]
System.out.println("Books available in the first library:");
[COLOR="#FF0000"]firstlibrary.printAvailableBooks();[/COLOR]
}}
Edited by 218845, 12 December 2011 - 12:31 AM.
#7
Posted 12 December 2011 - 12:47 AM
Did you even try to understand the errors?
What do you think this means?
What do you think this means?
cannot find symbol constructor Book(java.lang.String)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









