3 Replies - 1025 Views - Last Post: 03 November 2011 - 06:44 AM Rate Topic: -----

#1 slacoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 11-February 11

Book Manager

Posted 03 November 2011 - 12:33 AM

I am trying to make a simple book library and have come to a road block.


public class BookManager {  
	
	private static final int Max = 1000;
	private Book[]bookList= new Book[Max];
	private Book1[] bookList1= new Book1[Max];
	public  int NumBooks=0;
	public int NumBooks1=0;

	// add a book
	public void addBook (Book i){
		bookList[NumBooks++] = i;
	}//end addBook

	public void addBooks (Book1 k){
		bookList1[NumBooks1++]=k;
	}
		
	// list all books
	public String toString() {
		String str = "";
		for(int i = 0; i < NumBooks; i++) {
			str = str + "\n" + (i+1) + ") " + bookList[i].toString();
		}
		return str;
	}

	public String toString1() {
		String str1 = "";
		for(int k = 0; k < NumBooks1; k++) {
			str1 = str1 + "\n" + (k+1) + ") " + bookList1[k].toString1();
		}
		return str1;
	}

	public static void main(String[] arg) {
		BookManager bm = new BookManager();
		Book book4 = new Book("1234-5678", "My Life");
		Book book5 = new Book("1111-2222", "My wife");
		Book book6 = new Book("3333-4444", "My Dog");
		
		bm.addBook(book4);
		bm.addBook(book5);
		bm.addBook(book6);
		
		BookManager bm1 = new BookManager();
		Book1 book1=new Book1("4444-5555", "My Cat");
		Book1 book2=new Book1("5555-6666", "My House");
		
		
		bm1.addBooks(book1);
		bm1.addBooks(book2);
		
		System.out.println("Updated book list: " + bm);
		System.out.println("The books in the library is :" + bm1);
	}
}




public class Book1 {
	public String isbn1;
	private String title1;
	

	public Book1 (String isb1, String tit1){
		isbn1=isb1;
		title1=tit1;
		
	}

	public String GetIsbn1(){
		return isbn1;
	}
	
	public String GetTitle1(){
		return title1;
	}

	public String toString1(){
		String str1;
		str1 = "Isbn:" +isbn1+ " Title:" +title1;
		return str1;
	}//end String

}



The output is:
Updated book list:
1) Isbn:1234-5678 Title:My Life
2) Isbn:1111-2222 Title:My wife
3) Isbn:3333-4444 Title:My Dog
The books in the library is :


I want to print the last two books (book1 and book2) but it does not come in the output. I have relayed the first 3 books under "BookManager bm" whereas the other two books are under "Bookmanager bm1". I dont know why it is not printing out for me. Hope someone can help me out.

Is This A Good Question/Topic? 0
  • +

Replies To: Book Manager

#2 slacoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 11-February 11

Re: Book Manager

Posted 03 November 2011 - 01:20 AM

any help??
Was This Post Helpful? 0
  • +
  • -

#3 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Book Manager

Posted 03 November 2011 - 01:38 AM

Might be because you're trying to copy the functionality of the Book class to Book1 class. Why make another Book class? I don't see any differences among them, except for the codes inside their methods. If you want the books for Book1 to show, copy the toString() method of Book1. Hey, toString1() isn't called anywhere, but toString()is recognized by the JRE.
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5846
  • View blog
  • Posts: 12,703
  • Joined: 16-October 07

Re: Book Manager

Posted 03 November 2011 - 06:44 AM

View Postslacoul, on 03 November 2011 - 03:33 AM, said:

I want to print the last two books (book1 and book2) but it does not come in the output


You added those to bm1, which you don't print out. If this is unclear, then I'm doubting you actually wrote this code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1