package org.cs212.hello;
import java.util.ArrayList;
public class MyLibrary {
ArrayList<Book> books;
ArrayList<Person> people;
String name;
public MyLibrary(String n)
{
name = n;
books = new ArrayList<Book>();
people = new ArrayList<Person>();
}
public ArrayList<Book> getBooks() {
return books;
}
public ArrayList<Person> getPeople() {
return people;
}
public String getName() {
return name;
}
public void addBook(Book b)
{
books.add(b);
}
public void addPerson(Person p)
{
people.add(p);
}
public void removePerson(Person p)
{
people.remove(p);
}
public void removeBook(Book b)
{
books.remove(b);
}
boolean checkOut(Book b, Person p)
{
if (b.getPerson() == null &&
getBooksForPerson(p).size() == p.getMaximumBooks())
{
b.setPerson(p);
return true;
}
else
{
return false;
}
}
boolean checkIn(Book b)
{
if (b.getPerson() != null)
{
b.setPerson(null);
return true;
}
else
{
return false;
}
}
ArrayList<Book> getBooksForPerson(Person p)
{
ArrayList<Book> result = new ArrayList<Book>();
for (Book x : books)
{
if (x.getPerson() != null &&
x.getPerson().getName().equals(p.getName())
)
result.add(x);
}
return result;
}
}
Thursday, July 15, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment