Professional Documents
Culture Documents
TaTrungHieu BC TH Lab4
TaTrungHieu BC TH Lab4
Object-Oriented Programming
Lab 04: Inheritance and Polymorphism
Contents
1. Creating the Book class...........................................................................................................................1
2. Creating the abstract Media class............................................................................................................3
3. Creating the CompactDisc class..............................................................................................................6
6.1. Create the Disc class extending the Media class.............................................................................6
6.2. Create the Track class.......................................................................................................................8
6.3. Open the CompactDisc class.........................................................................................................10
4. Create the Playable interface.................................................................................................................10
5. Update the Cart class to work with Media............................................................................................12
6. Update the Store class to work with Media...........................................................................................17
7. Constructors of whole classes and parent classes.................................................................................19
8. Unique item in a list..............................................................................................................................19
9. Polymorphism with toString() method..................................................................................................20
10. Sort media in the cart.........................................................................................................................21
11. Create a complete console application in the Aims class..................................................................22
Page 1 of 29
Tạ Trung Hiếu – 20204970
addAuthor(String authorName)
removeAuthor(String authorName)
Page 2 of 29
Tạ Trung Hiếu – 20204970
Page 3 of 29
Tạ Trung Hiếu – 20204970
Page 4 of 29
Tạ Trung Hiếu – 20204970
Page 5 of 29
Tạ Trung Hiếu – 20204970
Page 6 of 29
Tạ Trung Hiếu – 20204970
Page 7 of 29
Tạ Trung Hiếu – 20204970
Page 8 of 29
Tạ Trung Hiếu – 20204970
Page 9 of 29
Tạ Trung Hiếu – 20204970
removeTrack()
getLength() method
Page 10 of 29
Tạ Trung Hiếu – 20204970
Page 11 of 29
Tạ Trung Hiếu – 20204970
Page 12 of 29
Tạ Trung Hiếu – 20204970
Page 13 of 29
Tạ Trung Hiếu – 20204970
Page 14 of 29
Tạ Trung Hiếu – 20204970
Page 15 of 29
Tạ Trung Hiếu – 20204970
Page 16 of 29
Tạ Trung Hiếu – 20204970
Page 17 of 29
Tạ Trung Hiếu – 20204970
Page 18 of 29
Tạ Trung Hiếu – 20204970
Page 19 of 29
Tạ Trung Hiếu – 20204970
+ For the Track class: the title and the length are equal
9.
Poly
Page 20 of 29
Tạ Trung Hiếu – 20204970
Page 21 of 29
Tạ Trung Hiếu – 20204970
Page 22 of 29
Tạ Trung Hiếu – 20204970
Page 23 of 29
Tạ Trung Hiếu – 20204970
Page 24 of 29
Tạ Trung Hiếu – 20204970
Page 25 of 29
Tạ Trung Hiếu – 20204970
Page 26 of 29
Tạ Trung Hiếu – 20204970
Page 27 of 29
Tạ Trung Hiếu – 20204970
Kết quả chạy: Các chức năng hoạt động bình thường (ngoại trừ chức năng sắp xếp chưa hoàn thiện)
Page 28 of 29
Tạ Trung Hiếu – 20204970
Page 29 of 29