|
| 1 | +// Implement a class called Book with properties bookID, title, publisher which uses |
| 2 | +// the interfaces IDisplay and IInput |
| 3 | + |
| 4 | +import java.util.Scanner; |
| 5 | + |
| 6 | +public class Book implements IDisplay, IInput { |
| 7 | + Scanner input = new Scanner(System.in); |
| 8 | + private int bookID; |
| 9 | + private String title; |
| 10 | + private String publisher; |
| 11 | + |
| 12 | + // default constructor |
| 13 | + public Book() { |
| 14 | + this.bookID = 0; |
| 15 | + this.title = ""; |
| 16 | + this.publisher = ""; |
| 17 | + } |
| 18 | + |
| 19 | + public Book(int bookID, String title, String publisher) { |
| 20 | + this.bookID = bookID; |
| 21 | + this.title = title; |
| 22 | + this.publisher = publisher; |
| 23 | + } |
| 24 | + |
| 25 | + public int getBookID() { |
| 26 | + return bookID; |
| 27 | + } |
| 28 | + |
| 29 | + public void setBookID(int bookID) { |
| 30 | + this.bookID = bookID; |
| 31 | + } |
| 32 | + |
| 33 | + public String getTitle() { |
| 34 | + return title; |
| 35 | + } |
| 36 | + |
| 37 | + public void setTitle(String title) { |
| 38 | + this.title = title; |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | + public String getPublisher() { |
| 43 | + return publisher; |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + public void setPublisher(String publisher) { |
| 48 | + this.publisher = publisher; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void print() { // Print in one line |
| 53 | + System.out.println("Book ID: " + bookID + " Title: " + title + " Publisher: " + publisher); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void printDetails() { // Print in multiple Lines |
| 58 | + System.out.println("Book ID: " + bookID); |
| 59 | + System.out.println("Title: " + title); |
| 60 | + System.out.println("Publisher: " + publisher); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public void input() { |
| 65 | + |
| 66 | + System.out.println("Enter Book ID: "); |
| 67 | + bookID = input.nextInt(); |
| 68 | + |
| 69 | + System.out.println("Enter Title: "); |
| 70 | + title = input.next(); |
| 71 | + |
| 72 | + System.out.println("Enter Publisher: "); |
| 73 | + publisher = input.next(); |
| 74 | + |
| 75 | + } |
| 76 | +} |
| 77 | + |
0 commit comments