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.
 
 

60 lines
822 B

  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 Book newBook()
  15. {
  16. Book temp = new Book(id);
  17. books.add(temp);
  18. id++;
  19. return temp;
  20. }
  21. public Book newBook(String title)
  22. {
  23. Book temp = new Book(title, id);
  24. books.add(temp);
  25. id++;
  26. return temp;
  27. }
  28. public Book getBook(int index)
  29. {
  30. return books.get(index);
  31. }
  32. public Book getBook(String title)
  33. {
  34. for (int i = 0; i < books.size(); i++)
  35. {
  36. Book temp = books.get(i);
  37. if(temp.getTitle() == title)
  38. {
  39. return temp;
  40. }
  41. }
  42. System.out.println("Error 404 : Book not found");
  43. return newBook();
  44. }
  45. }