Question: IN JAVA: SongType class: Create a class called SongType Add private fields called String title, String genre, int duration. Add accessor methods and mutator methods
IN JAVA:
SongType class:
-
Create a class called SongType
-
Add private fields called String title, String genre, int duration.
-
Add accessor methods and mutator methods to get and set the above fields.
-
Add a constructor to SongType class that takes as parameters: title, genre and duration.
-
If you don't already have one, add a toString method to your SongType class.
SongDataBaseClient
Add a class SongDataBaseClient to the same project where you created SongType. As you complete various parts of the SongDataBase you will add to the SongDataBaseClient to test your changes. You can add all of the test code to main in this class if you like, or break it up.
SongDataBase
-
In the same project as the SongType class and SongDataBaseClient, create a class called SongDataBase
-
Add a private array of SongType songs (you can create an array of anything, even classes you create!). Also have a private integer field numSongs to keep count of songs in the database array songs.
-
Add a constructor to SongDataBase that takes as a parameter the maximum number of songs to hold. This constructor should:
-
create a SongType array of the size passed in.
-
initialize numSongs to zero.
-
In SongDataBaseClient create two instances of SongDataBase. One that will have a maximum of 3 songs, and one that will have a maximum of 10.
-
-
Add an accessor for numSongs called getNumSongs().
-
In SongDataBaseClient, call the getNumSongs() accessor for both of your song instances and verify that the size is zero.
-
-
Add a method, listSongs that:
-
Prints the number of songs in the database.
-
Moves through the array and prints out the songs preceded by the index of the song. This should use the SongType toString method. If there is a null at that index in the songs array, it prints nothing. Two examples (your calls will not look like right now this since you have added nothing).
-
Song Data Base with 5 songs:
Total Number of Songs 3
Index 0 : Name = TestSong0, Genre = test genre, Duration = 10.0
Index 1 : Name = TestSong1, Genre = test genre, Duration = 11.0
Index 2 : Name = TestSong2, Genre = test genre, Duration = 12.0
Song Data Base with 3 songs, with index 0 and 2 empty (value at those indices is equal to null):
Total Number of Songs 3
Index 1 : Name = TestSong1, Genre = test genre, Duration = 11.0
Index 3 : Name = TestSong3, Genre = test genre, Duration = 13.0
Index 4 : Name = TestSong4, Genre = test genre, Duration = 14.0
-
In SongDataBaseClient, call listSongs for both of your SongDataBase instances. They should both print:
Total Number of Songs 0
-
Add a method, addSong, that takes as parameters a title, genre, and int duration. It should return a boolean. In that method:
-
Walk through the array hunting for the first element equal to null.
-
If no entry is equal to null, return false. (if youre having issues determining if the entry is null, ASK!)
-
If an entry is equal to null, set that entry equal to a new SongType object that is constructed with the parameters passed into this method. Increment numSongs by 1 and then return true.
-
This method does not do any other checking. For example, you can add dozens of the exact same song (if there is space).
-
In SongDataBaseClient, for the first instance of SongDataBase try to add 4 songs. Verify that the last call returns false, and all other calls return true by printing their return values. Call listSongs for both instances. One should print 3 songs, once should print no songs.
-
In SongDataBaseClient, To your second instance of SongDataBase add two Songs and call listSongs. Add one more song and call listSongs. Verify the output is correct for both calls.
-
Add a method, removeSong, that takes as a parameter an index and returns a boolean. Logic for this method:
-
If the index passed in is not within the array bounds, return false.
-
If the element at the index specified is already null, return false.
-
If the element is not null, set it to null, decrement numSongs by 1 and return true.
-
In SongDataBaseClient for your first instance of SongDataBase call remove for a negative value and a value greater than the array size. Verify it returns false. Print numSongs and verify it is correct.
-
In SongDataBaseClient for your first instance of SongDataBase call remove on index 1. Call listSongs and verify that index 1 is no longer printed. Print numSongs and verify it is correct.
-
In SongDataBaseClient call removSong for index 1 again and verify it returns false.
-
In SongDataBaseClient for your first instance of SongDataBase call addSong. Call listSongs and verify that the song was placed at index 1.
-
My work for SongData:
public class SongType {
private String title; private String genre; private int duration; public SongType(String newTitle, String newGenre, int newDuration) { title = newTitle; genre = newGenre; duration = newDuration; } public String getTitle() { return title; } public void setTitle(String newTitle) { title = newTitle; } public String getGenre() { return genre; } public void setGenre(String newGenre) { genre = newGenre; } public int getDuration() { return duration; } public void setDuration(int newDuration) { duration = newDuration; } public boolean isGreater(int newDuration) { if(newDuration < duration) { return true; } else { return false; } } public String toString() { return "Title: " + title + ", Genre: " + genre + ", Duration: " + duration; } }
NEED HELP WITH SongDataBaseClient and SongDataBase classes
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
