Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

Use STL to build a heap

Answered: 1 week ago