Question
CSCI 2010 Programming Assignment 1 Learning Outcomes Maintain a collection of objects using an array. Construct a class that contains an array as a private
CSCI 2010 Programming Assignment 1
Learning Outcomes
- Maintain a collection of objects using an array.
- Construct a class that contains an array as a private instance variable.
- Construct methods with arrays as parameters and return values.
- Use partially filled arrays to implement a class where objects can be dynamically added.
- Implement searching and sorting algorithms.
Required Reading
Savitch Chapter 6, 7
Instructions
For this assignment you will be implementing an application that manages a music collection. The application will allow the user to add albums to the collection and create a playlist of songs from that collection. The collection, albums, and playlist should all be implemented using arrays.
The Song Class
The Song class has the following members:
- Private instance variables for the title, artist, and length of the song in seconds.
- A constructor that takes a title, artist, number of minutes, and number of seconds and creates a Song object. The length of the song is calculated by multiplying the number of minutes by 60 and adding the number of seconds.
- Accessor methods for the title, artist, and length.
- A method called display that displays a song in the following format:
- - Artist (Minutes:Seconds)
- display the seconds as a two-digit number you can use the format code %02d. This will add a leading zero if the number of seconds is less than 10.
The Album Class
The Album class has the following members:
- Private instance variables for the title, artist, and tracklist of the album. The tracklist should be an array of Song objects.
- A constructor that takes a title, artist, and an array of Song objects and initializes the private instance variables. The tracklist should be initialized by creating a new array and copying all of the Song objects from the array passed as a parameter.
- Accessor methods for the title and artist.
- A method called getNumTracks that returns the number of tracks on the album.
- A method called getTrack that takes a track number between 1 and the number of tracks, and returns the corresponding song. If the number provided is out of range, it returns null.
- A method called comesBefore that takes another album as a parameter and returns true if the album the method was called on comes before the album passed as a parameter. The order is determined by the artist first, then the title. Use compareToIgnoreCase and equalsIgnoreCase to do the artist and title comparisons.
- A method called displayAlbum that displays the title, artist, and number of tracks in the following format:
- - Artist (NumTracks tracks)
- the number of tracks is one, it should display 1 track in the parentheses.
- A method called displayTracklist that displays each track with the corresponding track number before it. Use the format code %2d to align the track numbers to the right.
The AlbumCollection Class
The AlbumCollection class has the following members:
- A public named constant for the maximum number of albums allowed in a collection.
- Private instance variables for the number of albums in the collection, and an array of Album objects.
- A default constructor that initializes the number of albums to zero and the array to a new array that can store the maximum number of albums allowed.
- An accessor function for the number of albums.
- A boolean method called addAlbum that takes an Album as a parameter. If the collection is full it returns false. Otherwise, it stores the album in the next open spot in the array, and increments the number of albums.
- A method called findAlbum that takes a title and artist as parameters and uses a sequential search to find and return the first album it finds with the given title and artist. If no album is found, it returns null.
- A void method called sortAlbums that sorts all of the albums in the collection using selection sort, with the comesBefore method from the Album class determining the sorting order.
- A void method called displayAlbums that displays all of the albums in the collection.
- A void method called displaySongs that displays all of the albums in the collection along with their track lists.
The Playlist Class
The Playlist class has the following members:
- A public named constant for the maximum number of songs allowed in a playlist.
- Private instance variables for the number of songs in the playlist and an array of Song objects.
- A default constructor that initializes the number of songs to zero and the array to a new array that can store the maximum number of songs allowed.
- An accessor function for the number of songs.
- A method called getLength that returns the total length in seconds of the songs on the playlist.
- A boolean method called addSong that takes an Song as a parameter. If the playlist is full, it returns false. Otherwise, it stores the song in the next open spot in the array and increments the number of songs.
- A void method called display that displays all of the songs in the playlist, followed by the total length of the playlist in minutes and seconds.
- A void method called clear that empties out the playlist by setting the number of songs to 0. It does not have to go through the array and remove any songs.
The Main Class
The main class should be called YourlastnameProgram1 and has the following members:
- A private static void method called displayMenu that has no parameters and displays the following menu:
- one of the following: 1. Add an album to the collection 2. Display the albums in the collection 3. Display the songs in the collection 4. Sort the albums in the collection 5. Add a song to the playlist 6. Display the playlist 7. Clear playlist 8. Exit the program
- A private static method called getChoice that takes no arguments, reads an integer from the user, and returns it.
- A private static method called createAlbum that does the following:
- Prompt the user for an album title.
- Prompt the user for an album artist.
- Prompt the user for the number of tracks on the album until the user enters a value greater than zero.
- Call the getTracklist method to prompt the user for the tracks on the album and get an array of Song objects.
- Create a new Album object with the title, artist, and track list provided and return it.
- A private static method called getTracklist that takes the number of tracks and the album artist as parameters and does the following:
- Prompt the user for the title and length in minutes and seconds for each track.
- Create a Song object for each track with the information provided and store it in an array of Song objects.
- Return the array of Song objects.
- A private static method called getAlbumFromCollection that takes an AlbumCollection as a parameter and does the following:
- Prompt for the title and artist to search for.
- Call the findAlbum method to find the album in the collection.
- If the album is not found, display a message indicating that the album is not in the collection, and go back to step 1.
- Otherwise return the album.
- A private static method called getSongFromAlbum that takes an Album as a parameter and does the following:
- Display the tracklist for the album.
- Prompt the user to choose a track number.
- Call the getTrack method to get the song with the given track number.
- If the track number is not valid, go back to step 2.
- Otherwise, return the song.
- A main function that does the following:
- Create an empty AlbumCollection and an empty Playlist
- Display a welcome message.
- Call displayMenu to display the menu.
- Call getChoice to get the users choice.
- If the choice is 1, call createAlbum to create a new album and add the album to the collection.
- If the choice is 2, display the albums in the collection.
- If the choice is 3, display the songs in the collection.
- If the choice is 4, sort the albums in the collection.
- If the choice is 5, call getAlbumFromCollection to select an album, call getSongFromAlbum to select a song, and add the song to the playlist.
- If the choice is 6, display the playlist.
- If the choice is 7, clear the playlist.
- If the choice is 8, display a thank you message.
- If the choice is any other value, display an error message.
- Go back to step 3 unless the choice was 8.
Notes and Comments
Upload your Java source files to the dropbox named Programming Assignment 1. The name of the source file for the main class must be your last name followed by Program1 with the extension .java.
Make sure to include comments with your name, a description of what the program does, the course (CSCI 2010), and the assignment name (Programming Assignment 1) at the beginning of all of your source files. Also make sure to add comments at the beginning of each of the methods you write describing what they do.
Make sure you only hand in the source files for your assignment, not the class files, or any other files that NetBeans creates.
Your programs must compile without errors in order to be graded. Once your program compiles make sure to test it using multiple test cases to see if it meets the requirements of the assignment.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started