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.
 
 

52 regels
779 B

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