Question: DVD . java and DVDCollection.java screenshots are attached here: DVDConsoleUI.java: import java.util. * ; / * * * This class is an implementation of DVDUserInterface

DVD.java and DVDCollection.java screenshots are attached here:
DVDConsoleUI.java:
import java.util.*;
/**
* This class is an implementation of DVDUserInterface
* that uses the console to display the menu of command choices
*/
public class DVDConsoleUI implements DVDUserInterface {
private DVDCollection dvdlist;
private Scanner scan;
public DVDConsoleUI(DVDCollection dl){
dvdlist = dl;
scan = new Scanner(System.in);
}
public void processCommands()
{
String[] commands ={"Add/Modify DVD",
"Remove DVD",
"Get DVDs By Rating",
"Get Total Running Time",
"Save and Exit"};
int choice;
do {
for (int i =0; i commands.length; i++){
System.out.println("Select "+ i +": "+ commands[i]);
}
try {
choice = scan.nextInt();
scan.nextLine();
switch (choice){
case 0: doAddOrModifyDVD(); break;
case 1: doRemoveDVD(); break;
case 2: doGetDVDsByRating(); break;
case 3: doGetTotalRunningTime(); break;
case 4: doSave(); break;
default: System.out.println("INVALID CHOICE - TRY AGAIN");
}
} catch (InputMismatchException e){
System.out.println("INVALID CHOICE - TRY AGAIN");
scan.nextLine();
choice =-1;
}
} while (choice != commands.length-1);
}
private void doAddOrModifyDVD(){
// Request the title
System.out.println("Enter title");
String title = scan.nextLine();
if (title.equals("")){
return; // input was cancelled
}
title = title.toUpperCase();
// Request the rating
System.out.println("Enter rating");
String rating = scan.nextLine();
if (rating.equals("")){
return; // input was cancelled
}
rating = rating.toUpperCase();
// Request the running time
System.out.println("Enter running time");
String time = scan.nextLine(); // NOTE: time read in as a String!
if (time.equals("")){
return; // input was cancelled
}
// Add or modify the DVD (assuming the rating and time are valid)
dvdlist.addOrModifyDVD(title, rating, time);
// Display current collection to the console for debugging
System.out.println("Adding/Modifying: "+ title +","+ rating +","+ time);
System.out.println(dvdlist);
}
private void doRemoveDVD(){
// Request the title
System.out.println("Enter title");
String title = scan.nextLine();
if (title.equals("")){
return; // dialog was cancelled
}
title = title.toUpperCase();
// Remove the matching DVD if found
dvdlist.removeDVD(title);
// Display current collection to the console for debugging
System.out.println("Removing: "+ title);
System.out.println(dvdlist);
}
private void doGetDVDsByRating(){
// Request the rating
System.out.println("Enter rating");
String rating = scan.nextLine();
if (rating.equals("")){
return; // dialog was cancelled
}
rating = rating.toUpperCase();
String results = dvdlist.getDVDsByRating(rating);
System.out.println("DVDs with rating "+ rating);
System.out.println(results);
}
private void doGetTotalRunningTime(){
int total = dvdlist.getTotalRunningTime();
System.out.println("Total Running Time of DVDs: ");
System.out.println(total);
}
private void doSave(){
dvdlist.save();
}
}
DVDManager.java:
import java.util.*;
/**
* Program to display and modify a simple DVD collection
*/
public class DVDManager {
public static void main(String[] args)
{
DVDUserInterface dlInterface;
DVDCollection dl = new DVDCollection();
Scanner scan = new Scanner(System.in);
System.out.println("Enter name of data file to load:");
String filename = scan.nextLine();
dl.loadData(filename);
System.out.println("Input interface type: C=Console, G=GUI");
String interfaceType = scan.nextLine();
if (interfaceType.equals("C")){
dlInterface = new DVDConsoleUI(dl);
dlInterface.processCommands();
} else if (interfaceType.equals("G")){
dlInterface = new DVDGUI(dl);
dlInterface.processCommands();
} else {
System.out.println("Unrecognized interface type. Program exiting.");
System.exit(0);
}
}
}
DVDUserInterface.java:
public interface DVDUserInterface
{
void processCommands();
}
DVD . java and DVDCollection.java screenshots are

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 Programming Questions!