-
Notifications
You must be signed in to change notification settings - Fork 0
/
day-13-abstract-classes.js
70 lines (60 loc) · 1.39 KB
/
day-13-abstract-classes.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let _input = '';
let _index = 0;
process.stdin.on('data', (data) => {
_input = _input + data;
});
process.stdin.on('end', () => {
_input = _input.split(new RegExp('\n'));
main();
});
function readLine() {
return _input[_index++];
}
/** ** Ignore above this line. ****/
class Book {
constructor(title, author) {
if (this.constructor === Book) {
throw new TypeError('Do not attempt to directly instantiate an abstract class.');
} else {
this.title = title;
this.author = author;
}
}
display() {
console.log('Implement the \'display\' method!');
}
}
// Declare your class here.
class MyBook extends Book {
/**
* Class Constructor
*
* @param title The book's title.
* @param author The book's author.
* @param price The book's price.
**/
// Write your constructor here
constructor(title, author, price) {
super(title, author);
this.price = price;
}
/**
* Method Name: display
*
* Print the title, author, and price in the specified format.
**/
// Write your method here
display() {
console.log(`Title: ${this.title}`);
console.log(`Author: ${this.author}`);
console.log(`Price: ${this.price}`);
}
// End class
}
function main() {
let title = readLine();
let author = readLine();
let price = Number(readLine());
let book = new MyBook(title, author, price);
book.display();
}