Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I - The SimpleMusicTrack class For this assignment you must design a class named SimpleMusicTrack. This class must implement the PlayListTrackinterface given below. You

Part I - The SimpleMusicTrack class

For this assignment you must design a class named SimpleMusicTrack. This class must implement the PlayListTrackinterface given below. You must download this file and import it into your Project03 source code folder before you can start to implement your own SimpleMusicTrack class.

PlayListTrack.java

It is up to you how to represent the member variables of your SimpleMusicTrack class, but it must implement all of the methods given in the MusicTrack interface. Note in particular that it must implement thegetNextTrack(Scanner in) method that reads a single entry from a Scanner object (used with the input datafile).

In addition, your SimpleMusicTrack class must implement the following methods not provided in the interface, but are inherited from the Object class:

equals(Object obj) should return a true value if the name, artist and album in the two tracks are the same. Otherwise should return a false value.

toString() should return a string that contains the artist name followed by the track name with a single slash between them. The whole String should be surrounded by single quote marks (i.e. Elvis Presley / Jailhouse Rock).

As you write this class, write a test program to go along with it. Test each method as you write it, as we have discussed in class. You will need to start with a skeleton of your SimpleMusicTrack code that has each method in the interface written as a "stub" as seen in the Closed Lab code you have modified (i.e. code that does nothing but return a default value to allow the class to compile), and then you should modify your stub code one method at a time, testing each change you make. You will not need to submit this test program, but using it will make your code development much, much easier.

PlayListTrack Interface

import java.util.Scanner; public interface PlayListTrack { public String getName(); public void setName(String name); public String getArtist(); public void setArtist(String artist); public String getAlbum(); public void setAlbum(String album); public boolean getNextTrack(Scanner infile); // Attempts to read a playlist track entry from a Scanner object // Sets the values in the object to the values given in // the file // If it successfully loads the track, return true // otherwise, return false } 

The file format that the SimpleMusicTrack class should read is a simple one. An input file for multiple tracks would use this format:

track 1 name artist 1 name album 1 name ... track n name artist n name album n name 

A sample input file might look like this:

Blue Suede Shoes Elvis Presley Elvis Presley: Legacy Edition With A Little Help From My Friends The Beatles Sgt. Pepper's Lonely Hearts Club Band Seven Nation Army The White Stripes Elephant Long Line Of Cars Cake Comfort Eagle Head Like A Hole Nine Inch Nails Pretty Hate Machine 

The getNextTrack method should take a Scanner that has already opened an input file as a parameter. It should read the next three lines of the file into their appropriate member variables for the object. If the track is successfully loaded (i.e. all values are there and read from the file) it should return true. If there is a failure (for example, the code reads two lines and then the file ends without having a third line), then the method should return false. The method should NOT throw an exception error in the case of an error - it should catch the exception and return a value of false instead.

Part II - The SimplePlayList Class

Once you have coded and tested your SimpleMusicTrack class, you will need to write a SimplePlayList class that implements the PlayList interface given below. You must download this file and import it into your Project03 source code folder before you can start to implement your own SimplePlayList class.

PlayList.java

The SimplePlayList class stores music tracks in order - the first track added to the play list should be the first one removed from the play list. This data structure is known as a queue (or a first-in, first-out queue). As a hint, you can build your SimplePlayList class using an ArrayList of PlayListTrack objects to store the tracks (do not use an ArrayList of SimpleMusicTrack objects - it would work, but it may make your next Project assignment a bit more difficult). Again, as you write this class, write a test program to go along with it. Test each method as you write it, as we have discussed in class. You will need to start with a skeleton of your SimplePlayList code that has each method in the interface written as a "stub" as seen in the Closed Lab code you have modified (i.e. code that does nothing but return a default value to allow the class to compile), and then you should modify your stub code one method at a time, testing each change you make. You will not need to submit this test program, but using it will make your code development much, much easier.

PlayList interface

public interface PlayList { public PlayListTrack getNextTrack(); // Removes track from PlayList and returns it to the caller // Returns null if the PlayList is empty public PlayListTrack peekAtNextTrack(); // Returns next entry to the caller, but leaves it in the list public void addTrack(PlayListTrack track); // Adds this track to the playlist in the appropriate order public boolean isEmpty(); // Returns true if the playlist is empty } 

Part III - The PlayList Management Program

Once you have written and tested a SimpleMusicTrack class and a SimplePlayList class, it is time to use them to write a program to manage playlists. This program will simulate the playing of songs from a play list. For the SimplePlayList, the songs are removed from the playlist as they are played, so you know that you're at the end of the list when your list is empty. You should name this program Project03.java. Here is a sample transcript of the output of this program:

Enter database filename: proj03_input.txt Currently playing: No Song Playing Next track to play: Blue Suede Shoes / Elvis Presley [P]lay next track [A]dd a new track [Q]uit > p Currently playing: Blue Suede Shoes / Elvis Presley Next track to play: With A Little Help From My Friends / The Beatles [P]lay next track [A]dd a new track [Q]uit > p Currently playing: With A Little Help From My Friends / The Beatles Next track to play: Seven Nation Army / The White Stripes [P]lay next track [A]dd a new track [Q]uit > a Track name: Requiem For A Dying Song Artist name: Flogging Molly Album name: Float New track: Requiem For A Dying Song Artist: Flogging Molly Album: Float Are you sure you want to add this track [y/n]? y Currently playing: With A Little Help From My Friends / The Beatles Next track to play: Seven Nation Army / The White Stripes [P]lay next track [A]dd a new track [Q]uit > q Tracks remaining in play list ------------------------------------------------------------ 1 - Seven Nation Army / The White Stripes / Elephant 2 - Long Line Of Cars / Cake / Comfort Eagle 3 - Head Like A Hole / Nine Inch Nails / Pretty Hate Machine 4 - Requiem For A Dying Song / Flogging Molly / Float 

Ask the user to enter the name of the file that contains the play list data in the format described above in Part I.

Input the play list information from the file and store it in a SimplePlayList object (using SimpleMusicTrack objects).

Indicate what song is currently playing and what song is next in the play list. If there is no song currently playing (i.e. at the beginning right after the data file is loaded) the program should indicate this with a message No Song Playing. If the play list is empty and there is no next track, the program should indicate this with a message Play list is empty no more tracks.

Present the user a menu of three options play the next song in the play list, add a new song to the play list, or quit.

If the user chooses to play the next song, use the PlayList object to adjust the current track accordingly. Make sure your code does the right thing and gives an error message if the play list is empty and the user tries to play the next song.

If the user chooses to add a new track, prompt the user for the names of the song, artist and album. Verify that the user actually wants to add the track and if they say yes to this prompt add the track to the play list appropriately.

If the user chooses to quit, output a well-formatted report of the remaining songs in the play list, showing the name of the song, the artist and the album in the format indicated above. If the play list is empty, indicate this with the message No tracks remaining where the report data would normally be. When this report is finished the PlayList should be empty.

Extra Credit

For up to 2 points of extra credit on this project, implement two other PlayList data types. The first should be named PlayListStack and it should use a Stack as the underlying model for how the PlayList operates -- meaning that it should add and remove tracks in a Last In/First Out manner, and it should use a Stack as a private member variable to store tracks. The second should be named PlayListQueue and it should use a Queue as the underlying model for how the PlayList operates -- meaning that it should add and remove tracks in a First In/First Out manner, and it should use a Queue (LinkedList) as a private member variable to store tracks. Modify your Project03.java program to prompt the user for what kind of PlayList they want to use and make sure your code works appropriately for any version they choose. Your prompt can be as simple as asking them to enter a letter - 's' for Stack, 'q' for Queue and 'p' for a SimplePlayList type.

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

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions

Question

2. Define identity.

Answered: 1 week ago

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

4. Describe phases of majority identity development.

Answered: 1 week ago