We have a MediaPlayer interface and a concrete class AudioPlayer implementing the MediaPlayer interface. AudioPlayer can play mp3 format audio files by default. We are having another interface AdvancedMediaPlayer and concrete classes implementing the AdvancedMediaPlayer interface. These classes can play vlc and mp4 format files. We want to make AudioPlayer to play other formats as well. To attain this, we have created another class MediaAdapter which implements the MediaPlayer interface and uses AdvancedMediaPlayer objects to play the required format. AudioPlayer uses the class MediaAdapter passing it the desired audio type without knowing the actual class which can play the desired format. Main class, our demo class will use AudioPlayer class to play various formats. Create an interface MediaPlayer having an abstract method public void play(String audioType, String fileName);   Now create another interface AdvancedMediaPlayer having two abstract methods public void playVlc(String fileName);    public void playMp4(String fileName);   Now create concrete classes VLCPlayer , MP4Player both implements the AdvancedMediaPlayer interface.   Create another class MediaAdapter which implements the MediaPlayer Interface and also carry an object of AdvancedMediaPlayer as a data member.         AdvancedMediaPlayer advancedMusicPlayer;                   Provide a constructor as public MediaAdapter(String audioType) Now if audiotype is “VLC” then makes advancedMusicPlayer = new VlcPlayer();               otherwise if type is MP4 then you have to create mp4 object as                 advancedMusicPlayer = new Mp4Player(); Also implements the play method of MediaPlayer Interface which checks the  type of audio if its VLC then it will play VLC file otherwise it will plays MP4 file. Create a concrete class AudioPlayer which implements the MediaPlayer Interface. And have an instance of Media Adapter class as  MediaAdapter mediaAdapter;   This class will also implements the play method of the MediaPlayer Interface but this it will checks all formats if type is mp3 then it will play mp3 file, if the type is MP4 or VLC then it will call the play method of MediaAdapter class. Now in demo class write the following and observe the output AudioPlayer audioPlayer = new AudioPlayer();         audioPlayer.play("mp3", "beyond the horizon.mp3");       audioPlayer.play("mp4", "alone.mp4");       audioPlayer.play("vlc", "far far away.vlc");       audioPlayer.play("avi", "mind me.avi");

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

We have a MediaPlayer interface and a concrete class AudioPlayer implementing the MediaPlayer interface. AudioPlayer can play mp3 format audio files by default.

We are having another interface AdvancedMediaPlayer and concrete classes implementing the AdvancedMediaPlayer interface. These classes can play vlc and mp4 format files.

We want to make AudioPlayer to play other formats as well. To attain this, we have created another class MediaAdapter which implements the MediaPlayer interface and uses AdvancedMediaPlayer objects to play the required format.

AudioPlayer uses the class MediaAdapter passing it the desired audio type without knowing the actual class which can play the desired format. Main class, our demo class will use AudioPlayer class to play various formats.

  1. Create an interface MediaPlayer having an abstract method

public void play(String audioType, String fileName);

 

  1. Now create another interface AdvancedMediaPlayer having two abstract methods

public void playVlc(String fileName);

   public void playMp4(String fileName);

 

  1. Now create concrete classes VLCPlayer , MP4Player both implements the AdvancedMediaPlayer interface.

 

  1. Create another class MediaAdapter which implements the MediaPlayer Interface and also carry an object of AdvancedMediaPlayer as a data member.

        AdvancedMediaPlayer advancedMusicPlayer;

 

                Provide a constructor as

public MediaAdapter(String audioType)

Now if audiotype is “VLC” then makes

advancedMusicPlayer = new VlcPlayer();              

otherwise if type is MP4 then you have to create mp4 object as

                advancedMusicPlayer = new Mp4Player();

Also implements the play method of MediaPlayer Interface which checks the  type of audio if its VLC then it will play VLC file otherwise it will plays MP4 file.

  1. Create a concrete class AudioPlayer which implements the MediaPlayer Interface. And have an instance of Media Adapter class as

 MediaAdapter mediaAdapter;

 

This class will also implements the play method of the MediaPlayer Interface but this it will checks all formats if type is mp3 then it will play mp3 file, if the type is MP4 or VLC then it will call the play method of MediaAdapter class.

  1. Now in demo class write the following and observe the output

AudioPlayer audioPlayer = new AudioPlayer();

 

      audioPlayer.play("mp3", "beyond the horizon.mp3");

      audioPlayer.play("mp4", "alone.mp4");

      audioPlayer.play("vlc", "far far away.vlc");

      audioPlayer.play("avi", "mind me.avi");

 

Explain the work in your own words.

Use inheritance and Interface in java programming OOP.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY