Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Scanner;
- import java.awt.print.Book;
- import java.util.ArrayList;
- public class Zadacha4_2_2_Library {
- private String name;
- private HashMap<String, Zadacha4_2_1_book> books = new HashMap<String, Zadacha4_2_1_book>();
- public Zadacha4_2_2_Library(String name) {
- this.name = name;
- }
- public void addBook() {
- Scanner sc = new Scanner(System.in);
- System.out.printf("Adding book:%nZaglavie: ");
- String headline = sc.nextLine();
- System.out.print("Author: ");
- String author = sc.nextLine();
- System.out.print("Publisher: ");
- String publisher = sc.nextLine();
- System.out.print("Date Of Publish: ");
- int dateOfPublish = Integer.parseInt(sc.nextLine());
- System.out.print("ISBN: ");
- String isbn = sc.nextLine();
- books.put(isbn, new Zadacha4_2_1_book(headline, author, publisher, dateOfPublish, isbn));
- }
- public ArrayList<String> searchByAuthor(String bookAuthor) {
- ArrayList<String> found = new ArrayList<String>();
- for (String s : books.keySet()) {
- if (books.get(s).getAuthor().equalsIgnoreCase(bookAuthor)) {
- found.add(books.get(s).getIsbn());
- }
- }
- return found;
- }
- public void getInfo(String bookISBN) {
- if (books.containsKey(bookISBN)) {
- System.out.println();
- System.out.println("Headline: " + books.get(bookISBN).getHeadline());
- System.out.println("Author: " + books.get(bookISBN).getAuthor());
- System.out.println("Publisher: " + books.get(bookISBN).getPublisher());
- System.out.println("Date Of Publish:" + books.get(bookISBN).getDateOfPublishing());
- System.out.println("ISBN: " + books.get(bookISBN).getIsbn());
- } else {
- System.out.println("There is no book with this ISBN in the library");
- }
- }
- public void deleteBook(String bookISBN) {
- if (books.containsKey(bookISBN)) {
- books.remove(bookISBN);
- } else {
- System.out.println("There is no book with this name in the library");
- }
- }
- public String getName() {
- return name;
- }
- public HashMap<String, Zadacha4_2_1_book> getBooks() {
- return books;
- }
- public void setName(String name) {
- this.name = name;
- }
- }
Add Comment
Please, Sign In to add comment