Simple Sound Player
The goal of this assignment is to implement a simple sound player.
The application has been partially implemented, and you need to complete the missing bits.
When you open the project, you will see the class structure depicted below.
Three of the classes are fully implemented – you do not need to modify them. One class –
Player – has not been finished, and it is your job to finish implementation of this class.
Here is a quick overview over the existing classes:
This class presents the GUI (Graphical User Interface) of the application. That is: It draws the
main windows, the menu bar, the buttons, and all the other things you see on the screen.
However, it does not actually do anything much. If the user clicks a button, that call is just
passed on the the Player class.
This class represents a playable audio track. Investigate it: it has methods such as play, stop,
etc. You need to call these methods to make tracks play.
This represents a list of tracks that can be played. A playlist is built by specifying a folder on
disk with some audio files in it (by default the folder called audio inside the project folder). The
list will automatically load all audio files that it finds in that folder (wav, au and aiff formats
only. No MP3 – sorry.)
This class implements the logic of the player. This is where you have to do your work.
To complete this assignment you have to do the following:
• Implement the method stubs (methods with missing method bodies) in the Player
• The effect should be this: When a user selects a track in the list, the track information
(track name and playing duration) should be displayed in the interface.
• When a user clicks Play, the track should start playing. Stop should stop the track.
• When a user clicks Play without having selected a track, nothing should happen. (The
same goes for Stop.)
• When Play is clicked while a track is still playing, that playing track should stop and the
selected track should play from the start.
• When another track is selected in the track list while a track is playing, the playing
• getTrackName and getTrackInfo should return an empty string (a string of length zero)
if no track has been selected.
• You must complete all comments where they are missing (class and method comments).
• To achieve this, you have to make use of the ‘playList’ variable in the Player class to
retrieve tracks, and of the Track methods to start and stop playing the tracks. For example,
◦ currentTrack = playList.getTrack(2);
◦ would retrieve track number 2 from the play list and store it in a variable named
currentTrack. Test your code well. Your program should never display a runtime
Implement three more methods:
• one method named getNumberOfTracksPlayed that returns the number of tracks that
have been played (i.e. that have been started) since the player was started. The return
value should be an int.
• one method named getTotalPlayedTrackLength that returns the total playing time of all
tracks that have been played (or, to be more precise: started to play. We don’t care
whether they were played completely). The result is an int.
• one method named averageTrackLength that returns the average length of the tracks
played. The result is of type double.
When you have implemented these methods, open the SoundPlayerGUI class, find the method
named showAbout, and uncomment four lines of code as indicated in the comment
labeled “CHALLENGE TASK” in the source. The sound player’s About box (Help/About...) will
then call your methods to display this information.
Jump to Post
We are not here to solve your assignements by reading this big requirement. Paste your code here and ask for specific help.
Jump to Post
I'm no expert in Java.
But can you really assign an int to an instance of Track?
In the method
setTrack(int trackNumber)you're assigning the argument to
this.trackwhich is an instance of Track.
And also, in the method…
this.trackNamethat doesn't seem to be declared anywhere.
Jump to Post
when I compile it says I have incompatible types
Please post the full text of the compiler's error messages. They have useful info in them
Jump to Post
Look at line 37 in Player. There is a variable on that line that has a null value. Find the variable and then backtrack to see why that variable does not have a valid non-null value.
All 40 Replies
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.