Re: External method calls
System.out.println() takes a string as a parameter. So if you place a call to a method in it, that method needs to return a string and not be a void method.
If you're calling a method in the same class that you're in, you don't need to use "this". You can just use "listSongs()".
Your method getSongs(), just needs to call listSongs() to print, as you already have the print statement in listSongs().
So it can be written:
Code:
public Song getSongs()
{
listSongs();
}
But if that is all the code getSongs() is going to have, then you don't need that method as it's just doing the same as listSongs?
Re: External method calls
Quote:
Originally Posted by
FallenBlade
System.out.println() takes a string as a parameter. So if you place a call to a method in it, that method needs to return a string and not be a void method.
If you're calling a method in the same class that you're in, you don't need to use "this". You can just use "listSongs()".
Your method getSongs(), just needs to call listSongs() to print, as you already have the print statement in listSongs().
So it can be written:
Code:
public Song getSongs()
{
listSongs();
}
But if that is all the code getSongs() is going to have, then you don't need that method as it's just doing the same as listSongs?
I can't make it work with just
Code:
public Song getSongs()
{
listSongs();
}
because its not in the same class, the getSongs-method is in the class Artist and the listSongs-method in the Song-class.
Re: External method calls
Ah I see.
Ok, then I imagine this would work?
Code:
public Song getSongs()
{
song.listSongs();
}
Again, you don't need to call "this" as the variable name "song" should just work. And you don't need a println statement in both methods, as you have it in listSongs.
Re: External method calls
Quote:
Originally Posted by
FallenBlade
Ah I see.
Ok, then I imagine this would work?
Code:
public Song getSongs()
{
song.listSongs();
}
Again, you don't need to call "this" as the variable name "song" should just work. And you don't need a println statement in both methods, as you have it in listSongs.
Now it comes a new problem, it says that its missing a return statement..Is the whole idea with this method wrong or why doesn't it work? :S
Re: External method calls
By saying "public Song" the "Song" part means you need to return a Song object from the method. If you don't want to do that change the "Song" to void. Making it:
Code:
public void getSongs()
{
song.listSongs();
}
But where ever you are calling "getSongs()" in the rest of your code, you could just call "song.listSongs()".