Question: Need some help with a Java program about iterators and early exit loops. Given this class.... public class Song { private String artist; private String

Need some help with a Java program about iterators and early exit loops.

Given this class....

public class Song {

private String artist; private String title; private int length; private String genre;

public Song(String artistValue, String titleValue, int lengthValue, String genreValue) { artist = artistValue; title = titleValue; length = lengthValue; genre = genreValue; }

public String getArtist() { return artist; }

public String getTitle() { return title; }

public int getLength() { return length; }

public String getGenre() { return genre; }

public String toString() { return artist + " - " + title; } }

-Write a second class called SongLibrary that has two fields. One that stores the owner of the library, and the other is a collection of Song instances, in no particular order and without the posssibility of duplicates. Create a constructor that has one parameter for the name of the owner. Create an accessor for the name of the owner. After that, create a method called addSong with a parameter of a Song instance and it adds it to the collection.

~create a method called print that prints each Song in the collection, one per line.*** Make sure to use a while loop controlled by an iterator for all these methods ***

~create a method called getByArtist that has a parameter that is the name of an artist, it should return any Song in the collection by the artist or null if the collection does not contain any songs by the artist

~create a method called getGenreCount with a parameter that is the name of a genre. It should return the number of Songs in the collection that are part of that genre.

~create a method called duplicateTitles. This method should return whether or not there exist a pair of Songs in the collection that have the same title but are different artists.

~last method, called longestSong. this method should return the longest Song in the collection, or null if the collection if empty

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!