Practice Problems:   Creating Abstract Classes

Practice Problems: Creating Abstract Classes

This starter file contains classes that capture different media files (songs, movies, and audio books). Each media file class has a method called calculateFileSize that takes a string (one of "Low", "Med", or "High") indicating the desired media quality (lower quality files are smaller, but aren’t as clear as higher quality files).

At the bottom of the starter file, there is also a class that captures song purchases. Ideally, we would like to use this class to capture purchases of any kind of media.

Your job is to look for ways to use abstract classes and/or interfaces to (a) clean up the code, and (b) edit the MediaPurchase class to allow any kind of media to be supplied as the item field.

To check that you understand how to create MediaPurchase objects with individual media (a song, or a movie), also create an Examples class with some examples of MediaPurchases.

Here is one solution to this problem. You may have done something slightly different – feel free to ask us about it. This solution shows the minimum that you should have done to clean up the initial code.