-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook_author.dart
48 lines (39 loc) · 1.48 KB
/
book_author.dart
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
class Book {
String title;
String author;
int publicationYear;
int pagesRead;
static int totalBooks = 0;
Book(this.title, this.author, this.publicationYear, this.pagesRead) {
totalBooks++;
}
void read(int pages) {
pagesRead += pages;
}
int getPagesRead() => pagesRead;
String getTitle() => title;
String getAuthor() => author;
int getPublicationYear() => publicationYear;
int getBookAge() {
int currentYear = DateTime.now().year;
return currentYear - publicationYear;
}
}
void main() {
Book book1 = Book("Introduction to Algorithms", "Ronald Rivest", 1989, 120);
Book book2 = Book("Clean Code", "Robert Cecil Martin", 2012, 200);
Book book3 = Book("A Tour of C++", "Bjarne Stroustrup", 2013, 50);
book1.read(30);
book2.read(50);
book3.read(20);
print(
"Book 1 --- Book Name: ${book1.getTitle()}, Author: ${book1.getAuthor()}, Year: ${book1.getPublicationYear()}, Pages Read: ${book1.getPagesRead()}, Age: ${book1.getBookAge()} years");
print('');
print(
"Book 2 --- Book Name: ${book2.getTitle()}, Author: ${book2.getAuthor()}, Year: ${book2.getPublicationYear()}, Pages Read: ${book2.getPagesRead()}, Age: ${book2.getBookAge()} years");
print('');
print(
"Book 3 --- Book Name: ${book3.getTitle()}, Author: ${book3.getAuthor()}, Year: ${book3.getPublicationYear()}, Pages Read: ${book3.getPagesRead()}, Age: ${book3.getBookAge()} years");
print('');
print("Total Number of Books Created: ${Book.totalBooks}");
}