You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BookFactory.java 811 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Written by : Bin Hong Lee
  3. * Last edited : 4/27/2016
  4. */
  5. import java.util.*;
  6. class BookFactory
  7. {
  8. private List<Book> books = new ArrayList<Book>();
  9. private int id;
  10. public BookFactory()
  11. {
  12. id = 0;
  13. }
  14. public void newBook()
  15. {
  16. Book temp = new Book(id);
  17. books.add(temp);
  18. id++;
  19. }
  20. public void newBook(String title)
  21. {
  22. Book temp = new Book(title, id);
  23. books.add(temp);
  24. id++;
  25. }
  26. public Book getBook(int index)
  27. {
  28. return books.get(index);
  29. }
  30. public Book getBook(String title)
  31. {
  32. for (int i = 0; i < books.size(); i++)
  33. {
  34. Book temp = books.get(i);
  35. if(temp.getTitle() == title)
  36. {
  37. return temp;
  38. }
  39. }
  40. System.out.println("Error 404 : Book not found");
  41. Book empty = new Book();
  42. return empty;
  43. }
  44. }