+ 12
Has any one finished Kotlin final project? please help me!
You are building a Music Player app. You need to implement the MusicPlayer class, which should hold the track names as Strings in an array. The array is already defined in the given code. The player should support the following functions: add: add the given argument track to the tracks array. show: output all track names in the player on separate lines. play: start playing the first track by outputting "Playing name" where name is the first track name.
10 Respuestas
+ 9
class MusicPlayer {
private var songs: Array<String> = arrayOf()
//your code goes here
fun add(track : String){
songs += track
}
fun show() {
var song : String;
for (song in songs)
println(song)
}
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()
}
+ 5
based on your code:
https://code.sololearn.com/ct0v54GWMj38/?ref=app
fun show() {
var song : String;
for (song in songs)
println(song)
}
fun play() {
println("Playing "+songs[0]);
}
+ 4
Yes please.
+ 4
Thank you.
0
class MusicPlayer {
private var songs: Array<String> = arrayOf()
//your code goes here
fun add(track : String){
songs += track
}
fun show(){
for (element in songs) {
println(element)
}}
fun play(){
println("Now 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
class MusicPlayer {
private var songs: Array<String> = arrayOf()
//your code goes here
fun add(track : String){
songs += track
}
fun show() {
var song : String;
for (song in songs)
println(song)
}
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
in the main function simply instead of Array put Array<String>
- 2
Bugs in this program
- 2
Can help to find the bugs
- 2
When we enter stop the output is now playing haze