+ 1
Am having this error, unresolved reference: play, on MusicPlayer. My code below On Kotlin
class MusicPlayer { private var songs: Array<String> = arrayOf("Purple Haze","Under Pressure","Walk This Way","Playing Purple Haze","Stop") //your code goes here fun add(track: String): Unit{ songs += track } fun show(){ println("$songs[0]\n$songs[1]\n$[2]\n$songs[3]") } fun pay(){ val play = songs println("$songs[0]") } } fun main(args: Array<String>) { val m = MusicPlayer() while(true) { var input = readLine()!! if(input == "stop") { break } m.add(input) } m.show() m.play() }
10 Réponses
+ 3
Dave Enyi Did you name the function pay() in error? Did you mean to name it play()
+ 3
Dave Enyi congrats you did it👍👍
+ 3
Dave Enyi Good work!
+ 2
Hi Dave Enyi
I couldn't get any of your functions to work.
I suggest you work on one aspect of the code at a time, comment out the other calls.
Remember, you either need to return from a function, or print the result. fun add() does nothing at the moment.
Also, check your types, and you may wish to use a loop in your fun show() because the tests will have a varied number of songs.
Good luck
+ 2
You should try this :
class MusicPlayer {
private var songs: Array<String> = arrayOf()
//your code goes here
fun add(name:String){
songs += name
}
fun show(){
songs.forEach(){
item -> println(item)
}
}
fun play(){
println("Playing "+ songs[0])
}
}
fun main(args: Array<String>) {
val m = MusicPlayer()
while(true) {
var input = readLine()!!
if(input == "stop") {
break
}
m.add(input)
}
m.show()
m.play()
}
+ 2
Dave Enyi Congrats
Well done!
+ 1
Thanks
+ 1
My final code up and running thank you so much guyz much love 😍
I really appreciate you all for your support
class MusicPlayer {
private var songs: Array<String> = arrayOf()
//your code goes here
fun add(track: String): Array<String>{
songs = songs + track
return songs
}
fun show(){
for(track in songs.indices){
println(songs[track])
}
}
fun play(){
println("Playing "+songs[0])
}
}
fun main(args: Array<String>) {
val m = MusicPlayer()
while(true) {
var input = readLine()!!
if(input == "stop") {
break
}
m.add(input)
}
m.show()
m.play()
}
0
Yes and is throwing an error message saying unresolved reference: play
0
// here is the complete code but the play() is not working
class MusicPlayer {
private var songs: Array<String> = arrayOf("Purple Haze","Under Pressure","Walk This Way","Playing Purple Haze","Stop")
//your code goes here
fun add(track: String): Unit{
songs += track
}
fun show(){
println(songs[0])
println(songs[1])
println(songs[2])
println(songs[3])
}
fun play(){
}
}
fun main(args: Array<String>) {
val m = MusicPlayer()
while(true) {
var input = readLine()!!
if(input == "stop") {
break
}
m.add(input)
}
m.show()
m.play()
}