Advertisement
QwarkDev

prc 1 / java

Sep 1st, 2020
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. // Main.java
  2.  
  3. package com.company;
  4.  
  5. import java.io.*;
  6. import java.lang.String;
  7.  
  8. public class Main
  9. {
  10.     public static void main(String[] args)
  11.     {
  12.         Book[] books = new Book[10];
  13.  
  14.         for (int i = 0; i < 10; i++)
  15.         {
  16.             books[i] = new Book(String.format("Книга #%d", i + 1),  String.format("Книга #%d", i + 1));
  17.         }
  18.  
  19.         for (int i = 0; i < 10; i++)
  20.         {
  21.             System.out.println(books[i]);
  22.         }
  23.     }
  24. }
  25.  
  26. // Books.java
  27. package com.company;
  28.  
  29. public class Book
  30. {
  31.     private String bookName;
  32.     private String bookAuthor;
  33.  
  34.     public String getBookName()   { return bookName;   }
  35.     public String getBookAuthor() { return bookAuthor; }
  36.  
  37.     public void setBookName   (String value) { bookName = value;   }
  38.     public void setBookAuthor (String value) { bookAuthor = value; }
  39.  
  40.     public Book(String bookName, String bookAuthor)
  41.     {
  42.         this.bookName = bookName;
  43.         this.bookAuthor = bookAuthor;
  44.     }
  45.  
  46.     public Book() { }
  47.  
  48.     @Override
  49.     public String toString()
  50.     {
  51.         return String.format("Книга \"%s\" Автора \"%s\"", getBookName(), getBookAuthor());
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement