Question: Below you are given the declaration of the MediaPlayer interface: public interface MediaPlayer { / / Plays the media file void play ( String songName

Below you are given the declaration of the MediaPlayer interface: public interface MediaPlayer {// Plays the media file void play(String songName); // Pauses the currently playing media void pause(); // Stops the media playback void stop(); // Shows information about the current status String displayStatus(); } Implement the MediaPlayer interface in a class called SimpleMediaPlayer that includes: a private String attribute currentSong with corresponding getter getCurrentSong and setter setCurrentSong; a private String attribute status with corresponding getter. status can be one of the following values: "playing", "paused" or "idle"; a public constructor SimpleMediaPlayer() which sets currentSong to an empty string and sets status to "idle"; the implementation of the play(String songName) abstract method, which sets currentSong to the value of the parameter songName and sets status to "playing"; the implementation of the pause abstract method, which: if currentSong is not an empty string, set the status attribute to "paused"; if currentSong is an empty string, it does nothing; the implementation of the stop abstract method, which: if currentSong is not an empty string, set the status attribute to "idle" and currentSong to an empty string; if currentSong is an empty string, it does nothing; the implementation of the displayStatus() abstract method which should return: "Currently playing: [currentSong]" when currentSong is a non-empty string and status is "playing"; "Media player is [status]" when the status is not "playing". public interface MediaPlayer {// Plays the media file void play(String songName); // Pauses the currently playing media void pause(); // Stops the media playbac k void stop(); // Shows information about the current status String displayStatus(); } public class SimpleMediaPlayer implements MediaPlayer { private String currentSong; private String status; // Constructor initializing currentSong to an empty string and status to "idle" public SimpleMediaPlayer(){ this.currentSong =""; this.status = "idle"; }// Getter for currentSong public String getCurrentSong(){ return currentSong; }// Setter for currentSong public void setCurrentSong(String currentSong){ this.currentSong = currentSong; }// Getter for status public String getStatus(){ return status; }// Implementation of play method @Override public void play(String songName){ this.currentSong = songName; this.status = "playing"; }// Implementation of pause method @Override public void pause(){ if (!currentSong.isEmpty()){ this.status = "paused"; }}// Implementation of stop method @Override public void stop(){ if (!currentSong.isEmpty()){ this.currentSong =""; this.status = "idle"; }}// Implementation of displayStatus method @Override public String displayStatus(){ if (status.equals("playing")){ return "Currently playing: "+ currentSong; } else { return "Media player is "+ status; }} public static void main(String[] args){ SimpleMediaPlayer player = new SimpleMediaPlayer(); player.play("Song A"); System.out.println(player.displayStatus()); // Currently playing: Song A player.pause(); System.out.println(player.displayStatus()); // Media player is paused player.stop(); System.out.println(player.displayStatus()); // Media player is idle }}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!