Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 playString 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 playString 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 nonempty string and status is "playing"; "Media player is status when the status is not "playing". public interface MediaPlayer Plays the media file void playString 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 setCurrentSongString currentSong this.currentSong currentSong; Getter for status public String getStatus return status; Implementation of play method @Override public void playString 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 statusequalsplaying return "Currently playing: currentSong; else return "Media player is status; public static void mainString args SimpleMediaPlayer player new SimpleMediaPlayer; player.playSong A; System.out.printlnplayerdisplayStatus; Currently playing: Song A player.pause; System.out.printlnplayerdisplayStatus; Media player is paused player.stop; System.out.printlnplayerdisplayStatus; Media player is idle
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started