prateeksharma

books_01

Sep 21st, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner s = new Scanner(System.in);
  6. int n = s.nextInt();
  7. Book arr[] = new Book[n];
  8. if (n == 0) {
  9. System.out.println("N/A");
  10. } else {
  11. s.nextLine().trim();
  12. for (int i = 0; i < n; i++) {
  13. String book_name = s.nextLine().trim();
  14. String author_name = s.nextLine().trim();
  15. String isbn_no = s.nextLine().trim();
  16. arr[i] = new Book(book_name, author_name, isbn_no);
  17. }
  18. for (int i = 0; i < arr.length; i++) {
  19. System.out.println(arr[i]);
  20.  
  21. }
  22. }
  23. }
  24.  
  25.  
  26. }
  27.  
  28.  
  29. class Book {
  30. private String book_name;
  31. private String author_name;
  32. private String isbn_no;
  33.  
  34. public Book(String book_name, String author_name, String isbn_no) {
  35. this.book_name = book_name;
  36. this.author_name = author_name;
  37. this.isbn_no = isbn_no;
  38. }
  39.  
  40. @Override
  41. public String toString() {
  42. return "-----------------------------" + "\n" + "Book Name:\t" + book_name + "\n" + "Author Name:\t" + author_name + "\n" + "ISBN:\t" + isbn_no + "\n" + "-----------------------------";
  43.  
  44. }
  45. }
Add Comment
Please, Sign In to add comment