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
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