Correct the source code by only modifying the ??? locations. (There may be more
ID: 3709636 • Letter: C
Question
Correct the source code by only modifying the ??? locations. (There may be more than one word or symbol used.) Do not change any other code. Only modify the ??? pieces. You should correct DVD.java before correcting DVDCollection.java because DVDCollection creates objects from the DVD.java file.
// Replace the ??? through out the code with
// the appropriate Java code.
import javax.swing.JOptionPane;
import java.util.Scanner;
import java.io.File;
import java.io.???; // Replace the ??? with the appropriate code
public class DVDCollection {
public static void main(String[] args) ??? IOException { // Replace the ??? with the appropriate code
// Create a String to read each line from the input file
String input;
// Create a counter for the number of dvd objects read.
int count=0;
// Create a Book object
DVD dvdIn = ???; // Replace the ??? with the appropriate code
// Create an object for the input file
??? = new File("dvds.txt"); // Replace the ??? with the appropriate code
// Create a Scanner object for the input file
Scanner inFile = new Scanner(inFileObj);
while (???) { // Replace the ??? with the appropriate code
// Read the input file to obtain the title
input = inFile.nextLine();
// Set the title in the dvd object
dvdIn.setTitle(input);
// Read the input file to obtain the director
input = inFile.nextLine();
// Set the director in the dvd object
dvdIn.setDirector(input);
// Read the input file to obtain the length in minutes
input = inFile.nextLine();
// Set the length in the dvd object
dvdIn.setLength(???); // Replace the ??? with the appropriate code
// Read the input file to obtain the copyright year
input = inFile.nextLine();
// Set the copyright year in the dvd object
dvdIn.setCopyright(Integer.parseInt(input));
// Read the input file to obtain the maturity rating
input = inFile.nextLine();
// Set the rating in the dvd object
dvdIn.setRating(input);
// Read the input file to obtain the studio
input = inFile.nextLine();
// Set the studio in the dvd object
dvdIn.setStudio(input);
// Read the input file to obtain the bluray availability
input = inFile.nextLine();
// Set the bluray availability in the dvd object
dvdIn.setBluray(input.toUpperCase().???=='T'); // Replace the ??? with the appropriate code
// Read the input file to obtain the price
input = inFile.nextLine();
// Set the price in the dvd object
dvdIn.setPrice(Double.parseDouble(input));
// Read the input file to obtain the number sold
input = inFile.nextLine();
// Set the number sold in the dvd object
dvdIn.setSold(Integer.parseInt(input));
// Output the dvd object // Replace the ??? with the appropriate code
JOptionPane.showMessageDialog(???, ???, "DVD #"+ ++count +" in Collection", JOptionPane.INFORMATION_MESSAGE);
}
}
}
// *******************************************************
// * CIS 106 Midterm Exam - Programming Part
// * NAME: ??? Replace this text with your full name. 2 points
// * FILE: DVD.java
// *******************************************************
// Directions: Replace the ??? through out the code with
// the appropriate Java code. 2 points each.
public class DVD {
private String title; // Title of the DVD
// Replace the ??? with the appropriate code
private ??? director; // Director of the DVD
private int length; // Running time of the DVD in minutes
private int copyright; // Year of the copyright
private String rating; // DVD maturity rating
private String studio; // Studio that produces the DVD
// Replace the ??? with the appropriate code
private boolean ???; // Is the DVD available on BluRay?
private double price; // Price of the DVD
private int sold; // Weekly units sold nationally
// Constructor:
public DVD() {
title = "";
director = "";
length = 0;
copyright = 1900;
rating = "";
studio = "";
bluray = false;
price = 0.0;
sold = 0;
}
// Mutators:
public void setTitle(???) { // Replace the ??? with the appropriate code
this.title = ti;
}
public void setDirector(String dr) {
this.director = ???; // Replace the ??? with the appropriate code
}
public void setLength(int ln) {
this.length = ln;
}
public void setCopyright(int co) {
this.copyright = co;
}
public void setRating(String rt) {
this.rating = rt;
}
public void setStudio(String sdo) {
this.studio = sdo;
}
public void setBluray(boolean bry) {
this.bluray = bry;
}
public ??? setPrice(double prc) { // Replace the ??? with the appropriate code
this.price = prc;
}
public void setSold(int sl) {
this.sold = sl;
}
// Accessors:
public String getTitle(){
return title;
}
public String getDirector(){
return director;
}
public int getLength(){
???; // Replace the ??? with the appropriate code
}
public int getCopyright() {
return copyright;
}
public String getRating() {
return rating;
}
public String getStudio() {
return studio;
}
public boolean getBluray() {
return bluray;
}
public ??? getPrice() { // Replace the ??? with the appropriate code
return price;
}
public int getSold() {
return this.sold;
}
public String getPopularity() {
String pop;
if (getSold() >= 50000)
pop = "Very Popular";
??? (getSold() >= 1000) // Replace the ??? with the appropriate code
pop = "Popular";
else
pop = "Unpopular";
return pop;
}
public String toString() {
String returnValue = "";
??? "Title: "+getTitle()+" "; // Replace the ??? with the appropriate code
returnValue += "Director: "+getDirector()+" ";
returnValue += "Length: "+getLength()+" (minutes) ";
returnValue += "Copyright: "+getCopyright()+" ";
returnValue += "Rated: "+getRating()+" ";
returnValue += "Studio: "+getStudio()+" ";
returnValue += "Available on Bluray: "+(getBluray()?"Yes":"No")+" ";
returnValue += "Price: "+???("%3.2f",getPrice())+" "; // Replace the ??? with the appropriate code
returnValue += "Sales: "+getSold()+" ("+getPopularity()+") ";
return ???; // Replace the ??? with the appropriate code
}
}
Explanation / Answer
// *******************************************************
// * CIS 106 Midterm Exam - Programming Part
// * NAME: ??? Replace this text with your full name. 2 points
// * FILE: DVD.java
// *******************************************************
// Directions: Replace the ??? through out the code with
// the appropriate Java code. 2 points each.
public class DVD {
private String title; // Title of the DVD
// Replace the ??? with the appropriate code
private String director; // Director of the DVD
private int length; // Running time of the DVD in minutes
private int copyright; // Year of the copyright
private String rating; // DVD maturity rating
private String studio; // Studio that produces the DVD
// Replace the ??? with the appropriate code
private boolean bluray; // Is the DVD available on BluRay?
private double price; // Price of the DVD
private int sold; // Weekly units sold nationally
// Constructor:
public DVD() {
title = "";
director = "";
length = 0;
copyright = 1900;
rating = "";
studio = "";
bluray = false;
price = 0.0;
sold = 0;
}
// Mutators:
public void setTitle(String ti) { // Replace the ??? with the appropriate
// code
this.title = ti;
}
public void setDirector(String dr) {
this.director = dr; // Replace the ??? with the appropriate code
}
public void setLength(int ln) {
this.length = ln;
}
public void setCopyright(int co) {
this.copyright = co;
}
public void setRating(String rt) {
this.rating = rt;
}
public void setStudio(String sdo) {
this.studio = sdo;
}
public void setBluray(boolean bry) {
this.bluray = bry;
}
public void setPrice(double prc) { // Replace the ??? with the appropriate
// code
this.price = prc;
}
public void setSold(int sl) {
this.sold = sl;
}
// Accessors:
public String getTitle() {
return title;
}
public String getDirector() {
return director;
}
public int getLength() {
return length; // Replace the ??? with the appropriate code
}
public int getCopyright() {
return copyright;
}
public String getRating() {
return rating;
}
public String getStudio() {
return studio;
}
public boolean getBluray() {
return bluray;
}
public double getPrice() { // Replace the ??? with the appropriate code
return price;
}
public int getSold() {
return this.sold;
}
public String getPopularity() {
String pop;
if (getSold() >= 50000)
pop = "Very Popular";
else if (getSold() >= 1000) // Replace the ??? with the appropriate code
pop = "Popular";
else
pop = "Unpopular";
return pop;
}
public String toString() {
String returnValue = "";
returnValue += "Title: " + getTitle() + " "; // Replace the ??? with
// the appropriate code
returnValue += "Director: " + getDirector() + " ";
returnValue += "Length: " + getLength() + " (minutes) ";
returnValue += "Copyright: " + getCopyright() + " ";
returnValue += "Rated: " + getRating() + " ";
returnValue += "Studio: " + getStudio() + " ";
returnValue += "Available on Bluray: " + (getBluray() ? "Yes" : "No") + " ";
returnValue += "Price: " + System.out.format("%3.2f", getPrice()) + " "; // Replace
// the
// ???
// with
// the
// appropriate
// code
returnValue += "Sales: " + getSold() + " (" + getPopularity() + ") ";
return returnValue; // Replace the ??? with the appropriate code
}
}
import javax.swing.JOptionPane;
import java.util.Scanner;
import java.io.File;
import java.io.IOException; // Replace the ??? with the
public class DVDCollection {
public static void main(String[] args) throws IOException { // Replace the ??? with the appropriate code
// Create a String to read each line from the input file
String input;
// Create a counter for the number of dvd objects read.
int count=0;
// Create a Book object
DVD dvdIn = new DVD(); // Replace the ??? with the appropriate code
// Create an object for the input file
File inFileObj = new File("dvds.txt"); // Replace the ??? with the appropriate code
// Create a Scanner object for the input file
Scanner inFile = new Scanner(inFileObj);
while (inFile.hasNextLine()) { // Replace the ??? with the appropriate code
// Read the input file to obtain the title
input = inFile.nextLine();
// Set the title in the dvd object
dvdIn.setTitle(input);
// Read the input file to obtain the director
input = inFile.nextLine();
// Set the director in the dvd object
dvdIn.setDirector(input);
// Read the input file to obtain the length in minutes
input = inFile.nextLine();
// Set the length in the dvd object
dvdIn.setLength(Integer.parseInt(input)); // Replace the ??? with the appropriate code
// Read the input file to obtain the copyright year
input = inFile.nextLine();
// Set the copyright year in the dvd object
dvdIn.setCopyright(Integer.parseInt(input));
// Read the input file to obtain the maturity rating
input = inFile.nextLine();
// Set the rating in the dvd object
dvdIn.setRating(input);
// Read the input file to obtain the studio
input = inFile.nextLine();
// Set the studio in the dvd object
dvdIn.setStudio(input);
// Read the input file to obtain the bluray availability
input = inFile.nextLine();
// Set the bluray availability in the dvd object
dvdIn.setBluray(input.toUpperCase().charAt(0)=='T'); // Replace the ??? with the appropriate code
// Read the input file to obtain the price
input = inFile.nextLine();
// Set the price in the dvd object
dvdIn.setPrice(Double.parseDouble(input));
// Read the input file to obtain the number sold
input = inFile.nextLine();
// Set the number sold in the dvd object
dvdIn.setSold(Integer.parseInt(input));
// Output the dvd object // Replace the ??? with the appropriate code
JOptionPane.showMessageDialog(null, dvdIn, "DVD #"+ ++count +" in Collection", JOptionPane.INFORMATION_MESSAGE);
}
}
}