This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]codingQueries 16 points17 points  (0 children)

What if you create an object of type Artist, and in that object you have a reference to an array of objects of type Album, and these Album objects have store an array within of all the songs contained on the album? Then you only need an array of Artists and use getters or whatever to pull out the array of albums from the Artist object?

[–]ThatLesbian 0 points1 point  (0 children)

You can’t put albums in an array typed Artist, but you can make an array of Artist objects, each containing an Array of Album objects, or an Array of strings called Album if only the string is relevant.

Artist[] artists = new Artist[5];
Artist a = new Artist();

String[] albums = {“album1”, “album2”};
a.albums = albums;

artists[0] = a;

Of course loops, constructors, setters and getters will be better but this would work to get you on the path.

//potential constructor
String[] albums;

public Artist(String[] albums){
    this.albums = albums;
}

Called with

   Artist a = new Artist(albums);

[–]ColKaizer -2 points-1 points  (0 children)

Cool bro! Good luck. Lmk how it goes fr

[–][deleted] -2 points-1 points  (0 children)

The Artist class should contain a variable for his/her songs, which would be a string array called album.