Answered step by step
Verified Expert Solution
Link Copied!

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

7. List behaviors to improve effective leadership in meetings

Answered: 1 week ago

Question

6. Explain the six-step group decision process

Answered: 1 week ago