I've got this to turn the length of a music track into seconds, it works fine as a main methods (as below):
However, I'm putting it in my accessor method like this, and I'm getting an "Unreachable Statement" on the variable trackLengthToSecs.
Printable View
I've got this to turn the length of a music track into seconds, it works fine as a main methods (as below):
However, I'm putting it in my accessor method like this, and I'm getting an "Unreachable Statement" on the variable trackLengthToSecs.
Please repost the entire class reformatted. Good luck.
What in the trackDetails() method will be called after this statement has been reached?
Code:return trackName + "|" + trackLenght;
Is there a reason you use the name trackLenght, spelled incorrectly, while you use trackLengthToSecs, spelled correctly, or you're just too lazy to change it? ;)
Your error is here
After you've returned (a value), it stops with that method, so you can't put anything after that.Code:return trackName + "|" + trackLenght;
//Gets total minutes
int secInt1 = (int) trackLengthToSecs;
// Etc.
Btw.. why don't you just use this?
Code:public int toSeconds(final double time) {
return (int)(time)*60+(int)((time-mins)*100);
}
Supamagier, the amount of times i've spelt leng, lenth, length!!, wrong during this one little bit of java coding is amazing :P I now don't care how it's spelt, as long as it works :p.
Thanks for pointing out the above return is stopping it from working - I should of really realised that, I just thought it'd be more complicated :P.
That would possibly make more sense :P. The reason it was longer was because it took me a little while to work out how I wanted to do it so did it in a few stages - think I'll leave it like that for now (cheers for the better method though - made me actually think about shrinking stuff down after I've done it!!).
Also, I might copy the public int toSeconds(final double time) { bit. The question mentions using a toString method - is what you've got a to string, or am I reading too much into the to in front of seconds :P
It's spelled length ;)
Yea, you should ^^ beginner mistake. xD
You're welcome m8
Go ahead.
To return a String, just change public int into public String and change return blabla to return String.valueOf(blabla). :)