Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

-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

-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.

-The following are valid weight values; 140g, 180g, 200g

-The following are valid sizes; 7, 10, 12

-Getter, setters, toString

-play() method will display a simple message indicating that the record is being played.

You will add another layer to the class hierarchy with abstract PhysicalMedia which will subclass Compact Disc and VinylRecord and will inherit from MusicMedia. Also abstract DigitalMedia will subclass AudioFile and inherit from MusicMedia.

PhysicalMedia will have only two constructors, the default and the overloaded that will take parameters for title and artist and pass them to the super class MusicMedia

abstract DigitalMedia will do the same as PhysicalMedia with the addition of private String filePath. The filePath field will NOT have getters nor setters. DigitalMedia will also override toString() to display the filePath, title and artist.

Interface FileProcessor will define void save(String filePath) and void delete(String filePath), and will be implemented by DigitalMedia. The save method will set the DigitalMedia filePath field and display the message Saving the audioFile. The DigitalMedia delete method will display the message Deleting the audio file.

CompactDisc, no changes other than it will now extend PhysicalMedia

AudioFile, no changes other than it will now extend DigitalMedia

VinylRecord changes :

1.extends PhysicalMedia

2.Will add constants for default weight (40), default size (7), default track count (2)

3.Remaining constants for weights and sizes will be set in an initializer block.

4.Additional constructor for setting the title and artist that will also chain to the other overloaded constructor that uses the default constants to set the numberOfTracks, size, weightInGrams.

Lab4.java

This Driver class will create one of each of the PhysicalMedia types, assigning each address to a PhysicalMedia reference. It will create a DigitalMedia type assigning its address to a DigitalMedia reference. Display and the objects data to the console:

VinylRecord [numberOfTracks=2, size=7, weightInGrams=40, toString()=MusicMedia [title=Hey Jude, artist=The Bealtes]]

CompactDisc [numberOfTracks=5, toString()=MusicMedia [title=Golden Earing, artist=Moontan]]

Saving the audio file

AudioFile [fileName=A Girl Like You.mp3, fileSize=320, toString()=DigitalMedia [filePath=C://My Music/Smitherines/, toString()=MusicMedia [title=A Girl Like You, artist=The Smitherines]]]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+j on to staff their operations in the global marketplace.

Answered: 1 week ago