+ 16

Music Player

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. You can add a new item to an array using +=, for example: tracks += track https://code.sololearn.com/ck9NHmjfhHog/?ref=app

12th Feb 2021, 9:06 PM
𝐀𝐲𝐞𝐬𝐡𝐚 𝐍𝐨𝐨𝐫
𝐀𝐲𝐞𝐬𝐡𝐚 𝐍𝐨𝐨𝐫 - avatar
17 ответов
+ 12
Try this, the code is up and running 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() }
7th Mar 2021, 9:16 AM
Dave Enyi
Dave Enyi - avatar
+ 10
class Track: def __init__(self, title, next): self.title = title self.next = next class Player: def __init__(self): self.head = None def add(self, title): if not self.head: self.head = Track(title, None) return curr = self.head while curr.next: curr = curr.next curr.next = Track(title, None) p = Player() d = [] while True: x = input() if x == 'end': break p.add(x) d.append(x) for i in d: print (i)
29th May 2022, 5:56 PM
KGDWimalarathna
+ 6
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() }
26th Jul 2021, 5:02 AM
Ankit Chauhan
Ankit Chauhan - avatar
+ 4
class MusicPlayer { private var songs: Array<String> = arrayOf() //your code goes here fun add(song:String):Array<String> { songs += song return songs } fun show() { 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()!!.toString() if(input == "stop") { break } m.add(input) } m.show() m.play() }
14th Sep 2021, 8:02 AM
Brigido bergado jr
Brigido bergado jr - avatar
+ 1
Dave Enyi Thank You
16th Mar 2021, 6:07 PM
AbdulGhani Alaya
AbdulGhani Alaya - avatar
+ 1
🙏
6th Jul 2021, 3:53 PM
Ms. Cirty
Ms. Cirty - avatar
+ 1
class Track: def __init__(self, title, next): self.title = title self.next = next class Player: def __init__(self): self.head = None def add(self, title): if not self.head: self.head = Track(title, None) return curr = self.head while curr.next: curr = curr.next curr.next = Track(title, None) p = Player() d = [] while True: x = input() if x == 'end': break p.add(x) d.append(x) for i in d: print (i)
16th Aug 2022, 3:03 PM
Tsion Hailye Tasew
Tsion Hailye Tasew - avatar
0
Thank you i have learnt something on you.
28th Jun 2021, 9:18 PM
SAID MAKAMBA SALUM
SAID MAKAMBA SALUM - avatar
0
Copy this code correct answer and like thank you
14th Sep 2021, 8:03 AM
Brigido bergado jr
Brigido bergado jr - avatar
0
Alessio Pustorino !! The :Array part after the "fun add" was what I had missed. Thank you. Do you happen to know why it is needed?
1st Dec 2021, 10:51 AM
Ausgrindtube
Ausgrindtube - avatar
0
class MusicPlayer { private var songs: Array<String> = arrayOf() //your code goes here fun add(input: String){ songs += input } fun show(){ songs.forEach{ println(it) } } 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() }
24th Feb 2022, 10:01 AM
Md. Al-Amin
Md. Al-Amin - avatar
0
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() }
17th Sep 2022, 3:08 AM
Kanisak Shakya
Kanisak Shakya - avatar
0
class Track: def __init__(self, title, next): self.title = title self.next = next class Player: def __init__(self): self.head = None def add(self, title): if not self.head: self.head = Track(title, None) return curr = self.head while curr.next: curr = curr.next curr.next = Track(title, None) p = Player() d = [] while True: x = input() if x == 'end': break p.add(x) d.append(x) for i in d: print (i)
14th Nov 2022, 8:02 AM
Pooja Patel
Pooja Patel - avatar
0
All are wrong answer, Try mine class MusicPlayer { private var tracks: Array<String> = arrayOf() fun add(track: String) { //your code goes here tracks += track } fun show() { //your code goes here for (track in tracks){ println(track) } } fun play() { //your code goes here println("Playing ${tracks[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() }
28th Nov 2022, 5:02 AM
Imteyaz Ahmad
Imteyaz Ahmad - avatar
0
class Track: def __init__(self, title, next): self.title = title self.next = next class Player: def __init__(self): self.head = None def add(self, title): if not self.head: self.head = Track(title, None) return curr = self.head while curr.next: curr = curr.next curr.next = Track(title, None) p =Player() while True: x =input() if x == 'end': break p.add(x) n = p.head while n!= None: print(n.title) n = n.next # it may be work
24th Dec 2022, 6:44 PM
Aniket Pawar
Aniket Pawar - avatar
0
class MusicPlayer: def __init__(self): # Initialize an empty array to store track names self.tracks = [] # Function to add a new track MusicPlayerc(https://sites.google.com/site/legitticketsites/viagogo-es-seguro) def add(self, track): self.tracks += [track] # Add the track to the array # Function to show all tracks def show(self): for track in self.tracks: print(track) # Output each track on a separate line # Function to play the first track def play(self): if self.tracks: # Check if there are any tracks print(f"Playing {self.tracks[0]}") # Output the first track else: print("No tracks to play") # Handle empty track list
16th Oct 2024, 10:47 AM
SHOKH Ganiyeva
SHOKH Ganiyeva - avatar
0
This is a solid approach to creating a Music Player app! Implementing the MusicPlayer class with functions to add, show, and play tracks will make it user-friendly and functional. For more insights into building comprehensive music apps, check out this guide: https://www.cleveroad.com/blog/how-to-make-a-music-app-like-pandora--step-by-step-guide-with-detailed-estimation/.
5th Nov 2024, 3:38 PM
Vivienne Medrano