-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.dart
More file actions
38 lines (30 loc) · 1.39 KB
/
book.dart
File metadata and controls
38 lines (30 loc) · 1.39 KB
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
void main(){
print(" **** Module 5 – Assignment **** ");
print(" ");
Book himu = Book('Himu', 'Humayun Ahmed', 255); // Himu is an object of class Book.
print(himu.title);
print(himu.author);
print('Original price of the book ${himu.title} is ${himu.price} TK');
print("After you get discount ${himu.discountedPrice(10)} TK");
print(' ');
Book misirAli = Book('Misir Ali', 'Humayan Ahmed', 180); // misirAli is an object of class Book.
print(misirAli.title);
print(misirAli.author);
print('Original price of the book ${misirAli.title} is ${misirAli.price} TK');
print("After you get discount ${misirAli.discountedPrice(5)} TK");
}
// The Book class represents a book with a title, author, and price
class Book{
late String title; // Title is an instance variable of the Book class.
late String author; // Author is an instance variable of the Book class.
late double price; // Price is a instance variable of the Book class.
// Constructor to initialize Book object with title, author, and price
Book(this.title, this.author, this.price){
}
// Method to calculate and return the discounted price based on a given percentage
discountedPrice(double discountPercent){
double discountAmount = (discountPercent * price) /100;
double discountedPrice = price - discountAmount;
return discountedPrice; // Return the final price after applyng discount
}
}