+ 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.

25th Feb 2021, 4:48 PM
S.Raghunath
S.Raghunath - avatar
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() }
22nd Mar 2021, 11:44 AM
Namrata Dattani
Namrata Dattani - avatar
+ 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]); }
25th Feb 2021, 5:57 PM
visph
visph - avatar
+ 4
Yes please.
23rd Mar 2021, 3:12 PM
S.Raghunath
S.Raghunath - avatar
+ 4
Thank you.
23rd Mar 2021, 3:15 PM
S.Raghunath
S.Raghunath - avatar
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() }
23rd Mar 2021, 3:14 PM
Ravi Kumar
Ravi Kumar - avatar
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() }
14th Nov 2022, 8:36 AM
geg
0
in the main function simply instead of Array put Array<String>
14th Nov 2022, 8:37 AM
geg
- 2
Bugs in this program
23rd Mar 2021, 3:08 PM
Ravi Kumar
Ravi Kumar - avatar
- 2
Can help to find the bugs
23rd Mar 2021, 3:09 PM
Ravi Kumar
Ravi Kumar - avatar
- 2
When we enter stop the output is now playing haze
23rd Mar 2021, 3:13 PM
Ravi Kumar
Ravi Kumar - avatar