Source code: ================================= public interface RemoteControl {
ID: 3851162 • Letter: S
Question
Source code:
=================================
public interface RemoteControl {
public void homeBtn();
public void internetBtn();
public void navRightBtn();
public void navUpBtn();
public void navDownBtn();
public void playBtn();
public void stopBtn();
public void pauseBtn();
public void fFwdBtn();
public void fRevBtn();
public void skipSceneFwdBtn();
public void skipSceneRevBtn();
public void ejectBtn();
public void closeDrawerBtn();
public void openDrawerBtn();
public void acceptBtn();
public void powerBtn();
}
======================
public class DVDPlayer implements RemoteControl {
public void processRemoteCMD() {
powerBtn();
}
public void displayResultionDisplay() {
playBtn();
}
public void homeBtn() {
System.out.println("Here is the HOME Button");
System.out.println(" ");
internetBtn();
}
public void internetBtn() {
System.out.println("Now we are in internet menu");
System.out.println("Please click on Right Navigation button");
System.out.println(" ");
navRightBtn();
}
public void navRightBtn() {
System.out.println("Now we are in Right Navigation");
System.out.println("Now we are going to Up Navigation");
System.out.println(" ");
navUpBtn();
}
public void navUpBtn() {
System.out.println("We are in Up Navigation menu");
System.out.println("Cliking on Down Navigation menu");
System.out.println(" ");
navDownBtn();
}
public void navDownBtn() {
System.out.println("Now we are in Down Navigation menu");
System.out.println("Please press the play button to start");
System.out.println(" ");
playBtn();
}
public void playBtn() {
System.out.println("Now we are playing");
fFwdBtn();
}
public void stopBtn() {
System.out.println("Stopped the play");
ejectBtn();
}
public void pauseBtn() {
System.out.println("We just pause play");
stopBtn();
}
public void fFwdBtn() {
System.out.println("We are in fast forward stage");
fRevBtn();
}
public void fRevBtn() {
System.out.println("We are in fast Reverse stage");
skipSceneFwdBtn();
}
public void skipSceneFwdBtn() {
System.out.println("Now we are in skip Scene forward");
skipSceneRevBtn();
}
public void skipSceneRevBtn() {
System.out.println("Now we are in skip Scene Reverse");
pauseBtn();
}
public void ejectBtn() {
System.out.println("Removed the CD.");
openDrawerBtn();
}
public void closeDrawerBtn() {
System.out.println("close the Drawer");
}
public void openDrawerBtn() {
System.out.println("Now we are in opned the Drawer");
acceptBtn();
}
public void acceptBtn() {
System.out.println("accept the CD.");
closeDrawerBtn();
}
public void powerBtn() {
System.out.println("Start the power button");
homeBtn();
}
}
====================
import java.util.Scanner;
public class DVDSimulationDisplay {
static String value = null;
public static void displayCMD() {
DVDPlayer dvdPlayer = new DVDPlayer();
if (value.equalsIgnoreCase("1")) {
dvdPlayer.displayResultionDisplay();
} else {
dvdPlayer.processRemoteCMD();
}
}
public static void main(String a[]) {
System.out.println("Here are the DVD Player Remote methods");
System.out.println(" ");
System.out.println("please select displayResultionDisplay -1 and processRemoteCMD -2");
System.out.println(" ");
Scanner sc = new Scanner(System.in);
value = sc.nextLine();
DVDSimulationDisplay.displayCMD();
}
}
You are to design and then build a software simulation of a DVD player that also has WIFI capability and can connect to Netflix and play streaming video (we will keep it to Netflix at the moment). You are given the complete specification for the remote control until. It is modeled in the Analysis Classification model provided to you. Your task will be:
In assignment #4 to complete the analysis and design of the DVDPLayer class which is the model (in the MV two-tier arvchitecture) so that we can test out its functioning against the remote control before actually building the hardware DVD Player.
Implement the classes RemoteControl and DVDPlayer to demonstrate that the remote control can correctly and completely control the DVD player. For output of the DVD player functioning you can either direct status messages to the console, or build a GUI to demonstrate the DVD status. In either case, this is a view and must be totally separate from the DVDPlayer class.
System Requirements:
The remote control has been chosen. The following descriptions provide what is expected behaviour from the DVD player when each button is pressed:
HomeBtn: places the DVD player into home state and displays the home screen. If connected to the inetrnet, the connection is terminated. If a DVD is playing, it is stopped.
InternetBtn: If at home screen and internet service is available, connect to the last internet site visited (ex. Netflix). If there is no last site, go to “list of sites” screen. If no internet service is available, do nothing.
NavRightBtn: Move the cursor display to the right
NavLeftBtn: Move the cursor display to the left
NavUpBtn: Move the cursor display up one line
NavDownBtn: Move the cursor display down one line
PlayBtn: if a DVD is inserted and we are not in internet mode, begin playing the DVD. If
connected to an internet site, play (or select) the highlighted item (ex. Movie)
StopBtn: if playing a DVD, stop playing. If streaming an Internet movie stop and return to the
movie select screen.
PauseBtn: Pause playing the DVD or Internet movie
FFwdBtn: Fast-forward the DVD or Internet movie
FRevBtn: Fast-reverse the DVD or Internet movie
SkipSceneFwdBtn: skip one sceen forward on the DVD; if an internet movie, play in fast-forward
SkipSceneRevBtn: skip one sceen backward on the DVD; if an internet movie, play in fast-reverse
EjectBtn: If a DVD is in the drawer, open the drawer.
CloseDrawerBtn: Close the drawer if open.
OpenDrawerBtn: Open the drawer if closed.
AcceptBtn: (Internet only) Accept the highlighted item on the Internet site
PowerBtn: If DVD is currently ON, turn it OFF. If it is OFF, turn it ON.
In this part, you implement your model in Java. This part will not be marked according to how well the implementation behaves according to the description of the DVD. It will be marked according to how well you implemented your model from assignment #4. You must:
Accurately implement your model (behaviors, states, events and relationships)
Keep the model separate from the view – no view code in the model; no model code in the view
You may use either a GUI or console for the view (or a combination). For example, you can have
a window GUI representing the buttons of the remote, while displaying text on the console advising what the DVD is doing. Do not incorporate input/output into the console if you use a GUI for the remote.
You may
o Make minor adjustments to your model while implementing: you may discover that you identified attributes that are, in fact, redundent or unnecessary. You may also discover the need for attributes you did not identify in the model. Also methods may be identifed in your model that you now find unnecssary, or introduce methods that are not in the model because you discovered they were necessary.
o Any deviations from the model must be well documented (i.e. why you removed the characteristic, or why you introduced a characteristic)
Explanation / Answer
public class Player
{
private PlayList playList;
public Player()
{
playList = new PlayList("audio");
}
public PlayList getPlayList()
{
return playList;
}
public void play()
{
get player.play;
}
public class SoundPlayerGUI extends JFrame
implements ListSelectionListener
{
private static final String VERSION = "Version 1.0";
private JList fileList;
private JLabel infoLabel;
private Player player;
public SoundPlayerGUI()
{
super("kentSound");
player = new Player();
PlayList tracks = player.getPlayList();
makeFrame(tracks);
}
private void play()
{
player.play();
}
private void showInfo(String message)
{
infoLabel.setText(message);
}
private void stop()
{
player.stop();
}
private void quit()
{
System.exit(0);
}
private void showAbout()
{
String text = "kentSound " + VERSION;
JOptionPane.showMessageDialog(this,
text,
"About SoundPlayer",
JOptionPane.INFORMATION_MESSAGE);
}
public void valueChanged(ListSelectionEvent evt)
{
int selected = fileList.getSelectedIndex();
if(selected != -1) {
player.setTrack(selected);
}
showInfo(player.getTrackInfo());
}
private void makeFrame(PlayList tracks)
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel contentPane = (JPanel)getContentPane();
contentPane.setBorder(new EmptyBorder(6, 10, 10, 10));
contentPane.setLayout(new BorderLayout(8, 8));
JPanel leftPane = new JPanel();
{
leftPane.setLayout(new BorderLayout(8, 8));
// Create the scrolled list for file names
fileList = new JList(tracks.asStrings());
fileList.setForeground(new Color(212,212,255));
fileList.setBackground(new Color(0,85,150));
fileList.setSelectionBackground(new Color(212,212,255));
fileList.setSelectionForeground(new Color(0,45,75));
fileList.addListSelectionListener(this);
JScrollPane scrollPane = new JScrollPane(fileList);
scrollPane.setColumnHeaderView(new JLabel("Tracks"));
leftPane.add(scrollPane, BorderLayout.CENTER);
}
contentPane.add(leftPane, BorderLayout.CENTER);
// Create the center with image, text label, and slider
JPanel centerPane = new JPanel();
{
centerPane.setLayout(new BorderLayout(8, 8));
JLabel image = new JLabel(new ImageIcon("title.jpg"));
centerPane.add(image, BorderLayout.NORTH);
centerPane.setBackground(Color.WHITE);
infoLabel = new JLabel(" ");
infoLabel.setHorizontalAlignment(SwingConstants.CENTER);
infoLabel.setForeground(new Color(0,85,150));
centerPane.add(infoLabel, BorderLayout.CENTER);
centerPane.add(new JLabel(" "), BorderLayout.SOUTH);
}
contentPane.add(centerPane, BorderLayout.EAST);
// Create the toolbar with the buttons
JPanel toolbar = new JPanel();
{
toolbar.setLayout(new GridLayout(1, 0));
JButton button = new JButton("Play");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { play(); }
});
toolbar.add(button);
button = new JButton("Stop");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { stop(); }
});
toolbar.add(button);
}
contentPane.add(toolbar, BorderLayout.NORTH);
// building is done - arrange the components
pack();
// place this frame at the center of the screen and show
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation(d.width/2 - getWidth()/2, d.height/2 - getHeight()/2);
setVisible(true);
}
/**
* Create the main frame's menu bar.
*/
private void makeMenuBar()
{
final int SHORTCUT_MASK =
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
JMenuBar menubar = new JMenuBar();
setJMenuBar(menubar);
JMenu menu;
JMenuItem item;
// create the File menu
menu = new JMenu("File");
menubar.add(menu);
item = new JMenuItem("Quit");
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, SHORTCUT_MASK));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { quit(); }
});
menu.add(item);
// create the Help menu
menu = new JMenu("Help");
menubar.add(menu);
item = new JMenuItem("About SoundPlayer...");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { showAbout(); }
});
menu.add(item);
}
}
public class PlayList
{
private List<Track> tracks;
public PlayList(String directoryName)
{
tracks = loadTracks(directoryName);
}
public Track getTrack(int trackNumber)
{
return tracks.get(trackNumber);
}
public int numberOfTracks()
{
return tracks.size();
}
private List<Track> loadTracks(String dirName)
{
File dir = new File(dirName);
if(dir.isDirectory()) {
File[] allFiles = dir.listFiles();
List<Track> foundTracks = new ArrayList<Track>();
for(File file : allFiles) {
Track track = new Track(file);
if(track.isValid()) {
foundTracks.add(track);
}
}
return foundTracks;
}
else {
System.err.println("Error: " + dirName + " must be a directory");
return null;
}
}
/**
* Return this playlist as an array of strings with the track names.
*/
public String[] asStrings()
{
String[] names = new String[tracks.size()];
int i = 0;
for(Track track : tracks) {
names[i++] = track.getName();
}
return names;
}
}
public class Track
{
private Clip soundClip;
private String name;
public Track(File soundFile)
{
soundClip = loadSound(soundFile);
name = soundFile.getName();
}
public void play()
{
if(soundClip != null) {
soundClip.start();
}
}
public void stop()
{
if(soundClip != null) {
soundClip.stop();
}
}
public void rewind()
{
if(soundClip != null) {
soundClip.setFramePosition(0);
}
}
public String getName()
{
return name;
}
public int getDuration()
{
if (soundClip == null) {
return 0;
}
else {
return (int) soundClip.getMicrosecondLength()/1000000;
}
}
public void setVolume(int vol)
{
if(soundClip == null) {
return;
}
if(vol < 0 || vol > 100) {
vol = 100;
}
double val = vol / 100.0;
try {
FloatControl volControl =
(FloatControl) soundClip.getControl(FloatControl.Type.MASTER_GAIN);
float dB = (float)(Math.log(val == 0.0 ? 0.0001 : val) / Math.log(10.0) * 20.0);
volControl.setValue(dB);
} catch (Exception ex) {
System.err.println("Error: could not set volume");
}
}
public boolean isValid()
{
return soundClip != null;
}
private Clip loadSound(File file)
{
Clip newClip;
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(file);
AudioFormat format = stream.getFormat();
if ((format.getEncoding() == AudioFormat.Encoding.ULAW) ||
(format.getEncoding() == AudioFormat.Encoding.ALAW))
{
AudioFormat tmp = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
format.getSampleSizeInBits() * 2,
format.getChannels(),
format.getFrameSize() * 2,
format.getFrameRate(),
true);
stream = AudioSystem.getAudioInputStream(tmp, stream);
format = tmp;
}
DataLine.Info info = new DataLine.Info(Clip.class,
stream.getFormat(),
((int) stream.getFrameLength() *
format.getFrameSize()));
newClip = (Clip) AudioSystem.getLine(info);
newClip.open(stream);
return newClip;
} catch (Exception ex) {
return null;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.