I have two classes.CyberLibraray and CyberBook
These are the requirements:
Design a CyberLibrary class which houses CyberBooks. Because of local laws, the CyberLibrary
class has a limitation: the maximum number of books is 200.
The CyberLibrary has the following constructors:
Constructor #1: the default - Creates a CyberLibrary with the name: "BuffaloCyberLibrary"
which holds 150 CyberBooks.
Constructor #2: A constructor with two parameters: a String which is the name of the newly
created CyberLibrary and an int parameter which is the maximum number of CyberBooks that the
CyberLibrary can hold. If the number of books exceeds the maximum allowed, a default of 100 is
created . An error flag is set for later retrieval of this error.
The CyberLibrary has the following mutator methods:
Method #1: boolean addBook(CyberBook) - adds the CyberBook to the CyberLibrary
collection (finds the first free available space on the "bookshelf").
returns: a) true if book can be shelved
b) false if the CyberLibrary is full
The CyberLibrary has the following accessor methods:
Method #1: CyberBook Checkout( ), this method is used to checkout a random book
returns: a) any available book removed from the Library's bookshelf
b) null, if there are no more books available
Method #2: CyberBook findBookTitle( String title ), finds a CyberBook by title
returns: a) a CyberBook that matches title (and removed from the bookshelf)
b) null, if the book in not in the library
Method #2: CyberBook findBookISBN ( int ISBN ) - finds a CyberBook by ISBN.
returns: a) a CyberBook that matches the ISBN (and removed from the bookshelf)
b) null, if the book in not in the library
Method #3: boolean returnError( ), returns the value of the error flag
Method #4: int getFreeSpace( ), returns the number of free spaces on the library's bookshelf
Create a main( ) to test your program. The main ( ) should create a CyberLibrary named
"CyberButler" with space for 125 CyberBooks. Then create and add three CyberBooks with the
following titles and ISBNs [ {Java1, 1234}, { Java2, 3423}, {AdvJava1, 1298} ]. Test the methods:
findBookTitle( ) and findBookISBN( ) to see if they work properly (as an example, find the Java2
book). Print appropriate messages to the screen indicating the success/failure. Also try other tests to
see if all your methods work properly.
You must write a complete class, including constructors, all instance variables, and methods (as
detailed above). Use the appropriate access/visibility types, data types, and program logic.
This is what I have so far.
package cyberlibrary;
/**
*
* @author JoeLaptop
*/
public class CyberLibrary
{
private String LibraryName;
private static int MaxBooks;
public CyberLibrary()
{
LibraryName = "BufaloCyberLibrary";
MaxBooks = 150;
}
public CyberLibrary(String NewName,int NewMax)
{
System.out.println("Number " + MaxBooks);
LibraryName = NewName;
if(NewMax > 200)
MaxBooks = 100;
else
MaxBooks = NewMax;
System.out.println("Number " + MaxBooks);
}
public boolean addBook(String title,int isbn){
if(MaxBooks >= 200)return false;
else
MaxBooks = MaxBooks + 1;
CyberBook book1 = new CyberBook(title,isbn);
System.out.println("Book " + book1.getTitle( ));
System.out.println("Number " + MaxBooks);
System.out.println(LibraryName);
return true;
}
//CyberBook Checkout(){
// if(MaxBooks != 0)
// return CyberLibrary.this;
//}
public CyberBook findBookTitle(String title){
Object found;
CyberBook book1 = new CyberBook();
found = book1.getTitle();
System.out.println("Book Title1 " + found);
return (CyberBook) found;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
CyberLibrary CyberName1 = new CyberLibrary("CyberButler", 125);
CyberName1.addBook("Java1",1234);
CyberName1.addBook("Java2",3423);
CyberName1.addBook("AdvJava1",1298);
System.out.println("Book Title2 " + CyberName1.findBookTitle("Java1"));
}// main
}// CyberLibrary
And
package cyberlibrary;
public class CyberBook {
private String Title;
private int ISBN;
public CyberBook() {
}
// constructor
public CyberBook( String title, int isbn ) {
Title=title;
ISBN=isbn;
}
public String getTitle() {
return Title;
}
public int getISBN( ) {
return ISBN;
}
}
I need help with getting a return value for:
public CyberBook findBookTitle(String title)
It complies but it returns a null.
Here is my output:
run:
Number 0
Number 125
Book Java1
Number 126
CyberButler
Book Java2
Number 127
CyberButler
Book AdvJava1
Number 128
CyberButler
Book Title1 null
Book Title2 null
BUILD SUCCESSFUL (total time: 0 seconds)
This is a work in progress so some of the code is for troubleshooting.
Any help would be appreciated, I have already spent over 48 hrs on this, thanks.
I am using NetBeans 6.9.1 for editing.