A02

Due Date: Thursday, September 24
File(s) to be submitted: Playable.java, Rateable.java, MediaItem.java, Song.java, Podcast.java, AudioBook.java, PlayMedia.java


SUBMIT   /   Check

Interfaces & Inheritance

Summary

Your task is to create a media player that can handle songs, podcasts and audio books (possibly among others). All media items are playable, but each type plays in a different way and has different extra information.

Make good use of inheritance and polymorphism. Throw exceptions as appropriate.

Create a simple program (PlayMedia) that creates a List of MediaItems, populates the list, and then:

Note that that's three loops, not just one loop doing three things with each item.

There must be at least two of each kind of media item, and at least two ratable items, at least one each with and without ratings.

Design your program so that it may be extended easily for other playable and rateable media types.

Details

Here are the descriptions of each data type class and interface you need to create:

Playable
Any Playable object has play and getDescription methods.
Rateable
Any Rateable object has rate(double) and getRating methods.
MediaItem
A MediaItem has a title and a lengthInSeconds, and a constructor that initializes those fields.

It also has a displayInfo method that prints its title and length.

Finally, it has an abstract method play that each subclass has to implement.

This class is abstract, and so it cannot be instantiated on its own.

Song
A Song has an artist. Its play method prints a message like "Playing song <title> by <artist>."
Podcast
A Podcast has an artist. Its play method prints a message like "Streaming podcast <title>, with your host <host>."
AudioBook
An AudioBook has a narrator. Its play method prints a message like "You are listening to <title>, narrated by <narrator>."

Each of the media types must have a constructor that sets all the fields described above. It should not have setters for any field that isn't explicitly said to have a setter.

Songs are also rateable. It is rated out of five stars, and each new rating replaces any old rating. Each Song should start off unrated, and trying to get the rating of an unrated song should return NaN.


SUBMIT   /   Check