Question: This is in Java : I have an arrayList that stores albums. In the arrayList it holds the artist, title, Release year and genre. I
This is in Java :
I have an arrayList that stores albums. In the arrayList it holds the artist, title,
Release year and genre. I have to do the following :
Anytime a list of albums is displayed, the albums should be listed in alphabetical order by the artists name. To sort the albums, you will write your own Comparable interface. Do NOT use the Comparable interface that is build into the Java API.
I have to write my own comparable in an interface.
My code for the display method in the main class:
public static void displayAlbums(ArrayList albums, boolean numbered) {
for (int i = 0; i < albums.size(); i++) {
String numberingString;
if (numbered) {
numberingString = " " + Integer.toString(i + 1) + ". ";
} else {
numberingString = "";
}
Album album = albums.get(i);
System.out.println(numberingString + album.toString());
}
if (albums.size() > 0) {
System.out.println("");
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
