Help on ArrayList of Objects

Hello everyone, I am doing a project for university and I抦 having troubles with a method. I try to explain what it is?br>

I have two classes, one is a book class and the other is a catalogue which uses an ArrayList. Each book has a String description and a borrower number.

I have to do a method to search trough the books, but only if the search found ONE book I should be able to borrow that book, by changing the borrower number, which is set to 0 by default.

Can somebody give me a tip?

There is it the code.

public class Book

{

private String description;

private int borrowerNumber;

public Book(String theDescription)

{

borrowerNumber = 0;

description = theDescription;

}

public void print()

{

System.out.println(description);

}

public String getDescription()

{

return description;

}

public int getBorrowerNumber()

{

return borrowerNumber;

}

}

import java.util.ArrayList;

public class Catalogue

{

private ArrayList<Book> books;

private String entry;

private int borrower;

private int searchNumber;

private int yourID;

public Catalogue()

{

books = new ArrayList<Book>();

// searchNumber = 1;

}

public void addBook(String description)

{

books.add(new Book(description));

}

public void Search(String entry, int borrower)

{

searchNumber = 0;

for(Book book : books){

if (book.getDescription().equals(entry) || book.getDescription().contains(entry)){

System.out.println(searchNumber++ + " " + book.getDescription()); }

if (book.getBorrowerNumber() == 0 && book.getDescription().equals("")){

System.out.println(searchNumber+1 + " " + book.getDescription());}

if (book.getBorrowerNumber() == borrower && book.getBorrowerNumber() != 0){

System.out.println(searchNumber+1 + " " + book.getDescription());}

if (searchNumber > 0){

System.out.println("please search better");}

else{

book.getBorrowerNumber()= borrower;}

}

[2212 byte] By [virkofa] at [2007-11-27 1:48:50]
# 1
Crossposted. Ignore this thread. http://forum.java.sun.com/thread.jspa?threadID=5163333
warnerjaa at 2007-7-12 1:13:22 > top of Java-index,Development Tools,Java Tools...