Dimitar_Ivanov_16408

Zadacha4_2_2_Library

May 9th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3. import java.awt.print.Book;
  4. import java.util.ArrayList;
  5.  
  6. public class Zadacha4_2_2_Library {
  7. private String name;
  8. private HashMap<String, Zadacha4_2_1_book> books = new HashMap<String, Zadacha4_2_1_book>();
  9.  
  10. public Zadacha4_2_2_Library(String name) {
  11. this.name = name;
  12. }
  13.  
  14. public void addBook() {
  15. Scanner sc = new Scanner(System.in);
  16. System.out.printf("Adding book:%nZaglavie: ");
  17. String headline = sc.nextLine();
  18. System.out.print("Author: ");
  19. String author = sc.nextLine();
  20. System.out.print("Publisher: ");
  21. String publisher = sc.nextLine();
  22. System.out.print("Date Of Publish: ");
  23. int dateOfPublish = Integer.parseInt(sc.nextLine());
  24. System.out.print("ISBN: ");
  25. String isbn = sc.nextLine();
  26. books.put(isbn, new Zadacha4_2_1_book(headline, author, publisher, dateOfPublish, isbn));
  27. }
  28.  
  29. public ArrayList<String> searchByAuthor(String bookAuthor) {
  30. ArrayList<String> found = new ArrayList<String>();
  31.  
  32. for (String s : books.keySet()) {
  33. if (books.get(s).getAuthor().equalsIgnoreCase(bookAuthor)) {
  34. found.add(books.get(s).getIsbn());
  35. }
  36. }
  37.  
  38. return found;
  39. }
  40.  
  41. public void getInfo(String bookISBN) {
  42. if (books.containsKey(bookISBN)) {
  43. System.out.println();
  44. System.out.println("Headline: " + books.get(bookISBN).getHeadline());
  45. System.out.println("Author: " + books.get(bookISBN).getAuthor());
  46. System.out.println("Publisher: " + books.get(bookISBN).getPublisher());
  47. System.out.println("Date Of Publish:" + books.get(bookISBN).getDateOfPublishing());
  48. System.out.println("ISBN: " + books.get(bookISBN).getIsbn());
  49. } else {
  50. System.out.println("There is no book with this ISBN in the library");
  51. }
  52. }
  53.  
  54. public void deleteBook(String bookISBN) {
  55. if (books.containsKey(bookISBN)) {
  56. books.remove(bookISBN);
  57. } else {
  58. System.out.println("There is no book with this name in the library");
  59. }
  60. }
  61.  
  62. public String getName() {
  63. return name;
  64. }
  65.  
  66. public HashMap<String, Zadacha4_2_1_book> getBooks() {
  67. return books;
  68. }
  69.  
  70. public void setName(String name) {
  71. this.name = name;
  72. }
  73.  
  74. }
Add Comment
Please, Sign In to add comment