Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Lab: Create the following class hierarchy: MusicMedia An abstract class with fields for music title and artist. Constructor that takes parameters to set both
Java Lab:
Create the following class hierarchy:
- MusicMedia
- An abstract class with fields for music title and artist.
- Constructor that takes parameters to set both fields. Parameters must be validated appropriately before they are assigned to the fields. If either parameter is invalid throw an IllegalArgumentException and exit the program.
- Getter and setter for each field
- toString() to display the field values
- Abstract method void play()
- CompactDisc
- Inherits from MusicMedia
- Has a field to hold the number of tracks on the CD
- Constructor takes parameters for title, artist. The number of tracks. The number of tracks should be validated appropriately and an IllegalArgumentException will be thrown if the value is bad.
- Getter and setter for the number of tracks field
- toString that will display the number of tracks, title, and artist
- play() method will display a simple message indicating that the cd is being played.
- AudioFile
- Inherits from MusicMedia
- Fields for the file name and the file size in bytes per second (eg. 320 bps)
- Constructor with parameters for title, artist, filename, file size. File name and file size must be validated appropriately and an IllegalArgumentException will be thrown if the values are bad.
-
- Getters, setters toString
- play() method will display a simple message indicating that the file is being played.
- VinylRecord
- Inherits from MusicMedia
- Fields for the number of tracks, the size, and the weight in grams
- Constructor will take parameters for title, artist, number of tracks, size, and weight. Appropriate validations will be done and IllegalArgumentExeptions will be thrown when values are bad.
- Valid size will be either 12
- The following are valid weight values; 140g, 180g, 200g
- Getter, setters, toString
- play() method will display a simple message indicating that the record is being played.
- Driver class
- Will implement main(...)
- create instance of each subtype and assign the address to a MusicMedia reference
- display the objects field values
- call the play() methods
- Will implement main(...)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started