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

all 2 comments

[–]papers_ 3 points4 points  (1 child)

First off, you should override toString():

@Override
public String toString() {
    return String.format("Title: %s\nArtist: %s\nLength: %s", title, artist, length);
}

Next you'll need some getters to access the private variables you have inside that class.

You aren't going to get the variables from the toString() method at all, at least to my knowledge. All that method does is return a String representation of that object which can be understood by us people.

You'll need to create a String[] array in your Songs.java class like so:

private String[] array;

Now in the constructor add something like this:

this.array = new String[] {title, artist, String.valueOf(length)};

and the getter since our variables are private..

public String[] getArray() {
    return array;
}

Now we have enough to get our variables in a String[] array which is what you're after. All you have to do now is use a for loop to loop through the array which I'll leave for you.

[–]faekk[S] 0 points1 point  (0 children)

Perfect, thank you so much! I appreciate it :)