Question: Java Lab: Please look at the bullet points carefully as some of the questions posted over here are similar but this one is different and

Java Lab:

Please look at the bullet points carefully as some of the questions posted over here are similar but this one is different and needs to be coded from scratch. Thank you

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!