-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDay13.java
55 lines (46 loc) · 1.24 KB
/
Day13.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package HackerRank.CodingDays30;
import java.util.Scanner;
abstract class Book {
String title;
String author;
Book(String title, String author) {
this.title = title;
this.author = author;
}
abstract void display();
}
class MyBook extends Book{
int price;
/**
* Class Constructor
*
* @param title The book's title.
* @param author The book's author.
* @param price The book's price.
**/
MyBook(String bookTitle, String bookAuthor, int bookPrice) {
super(bookTitle, bookAuthor);
this.price = bookPrice;
}
/**
* Method Name: display
*
* Print the title, author, and price in the specified format.
**/
void display() {
System.out.println("Title: " + title);
System.out.println("Author: " + author);
System.out.println("Price: " + price);
}
}
public class Day13 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String title = scanner.nextLine();
String author = scanner.nextLine();
int price = scanner.nextInt();
scanner.close();
Book book = new MyBook(title, author, price);
book.display();
}
}