Advertisement
16112

Курсова Работа 2 - 4.3 Клас библиотека

Apr 21st, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1. package testing;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Library {
  6.     private String libraryName;
  7.     private ArrayList<Books> list = new ArrayList<>();
  8.  
  9.     public Library(String libraryName) {
  10.         this.libraryName = libraryName;
  11.     }
  12.  
  13.     public void addBook(Books newBook) {
  14.         this.list.add(newBook);
  15.     }
  16.  
  17.     public void print(String author) {
  18.         for (Books books : list) {
  19.             if (author.equals(books.getAuthor())) {
  20.                 System.out.println(books.getTitle());
  21.                 System.out.println(books.getYear());
  22.                 System.out.println(books.getPublishingHouse());
  23.                 System.out.println(books.getIsbn());
  24.             }
  25.         }
  26.         System.out.println();
  27.     }
  28.  
  29.     public void print() {
  30.         for (Books books : list) {
  31.             System.out.println(books.getTitle());
  32.             System.out.println(books.getAuthor());
  33.             System.out.println(books.getYear());
  34.             System.out.println(books.getPublishingHouse());
  35.             System.out.println(books.getIsbn());
  36.             System.out.println();
  37.  
  38.         }
  39.         System.out.println();
  40.         System.out.println();
  41.     }
  42.  
  43.     public void delete(String author) {
  44.         for (int i = 0; i < list.size(); i++) {
  45.             if (author.equals(list.get(i).getAuthor())) {
  46.                 list.remove(i);
  47.             }
  48.         }
  49.     }
  50. }
  51.  
  52. ------------------------------------------------------------------------------------------------------------------------------
  53.  
  54. package testing;
  55.  
  56. import java.util.ArrayList;
  57.  
  58. public class Books {
  59.     private String title;
  60.     private String author;
  61.     private String publishingHouse;
  62.     private int year;
  63.     private String isbn;
  64.  
  65.     public String getTitle() {
  66.         return title;
  67.     }
  68.  
  69.     public String getAuthor() {
  70.         return author;
  71.     }
  72.  
  73.     public String getPublishingHouse() {
  74.         return publishingHouse;
  75.     }
  76.  
  77.     public int getYear() {
  78.         return year;
  79.     }
  80.  
  81.     public String getIsbn() {
  82.         return isbn;
  83.     }
  84.  
  85.     public Books(String title, String author, String publishingHouse, int year, String isbn) {
  86.         this.title = title;
  87.         this.author = author;
  88.         this.publishingHouse = publishingHouse;
  89.         this.year = year;
  90.         this.isbn = isbn;
  91.     }
  92. }
  93.  
  94. ------------------------------------------------------------------------------------------------------------------------------
  95.  
  96. package testing;
  97.  
  98. import java.util.Scanner;
  99.  
  100. public class Test {
  101.     public static void main(String[] args) {
  102.         Scanner scanner = new Scanner(System.in);
  103.         Library library = new Library("Sun");
  104.         Books book1 = new Books("The Shining", "Stephen King", "Viking", 1977, "9780446390576");
  105.         Books book2 = new Books("Don't touch this book", "Jan van Helsing", "Ama Deus Verlag", 2006, "3938656212");
  106.         Books book3 = new Books("It", "Stephen King", " Viking", 1986, "0-670-81302-8");
  107.         Books book4 = new Books("The Maze Runner", "James Dashner", "Delacorte Press", 2009, "978-0-385-73794-4");
  108.         library.addBook(book1);
  109.         library.addBook(book2);
  110.         library.addBook(book3);
  111.         library.addBook(book4);
  112.  
  113.         library.print();
  114.         library.delete("Stephen King");
  115.         library.print();
  116.  
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement