Question

In: Computer Science

CompSci 251: Intermediate Computer ProgrammingLab 3 – 2019 Introduction This lab will focus on creating a...

CompSci 251: Intermediate Computer ProgrammingLab 3 – 2019

Introduction

This lab will focus on creating a Movie class conforming to the diagram above. From this class Movie objects can be instantiated and used in a running program. I have provided a mostly completely driver, you will need to add a few lines of code where specified.

What you need to do

  •  Declare you instance variables at the top of the class.

  •  Write a specifying constructor. No default constructor is required.

  •  Write getName and setName. There are no restrictions on the setting the name.

  •  Write getMinutes and setMinutes. When setting minutes, it is not allowed to be negative.

  •  Write getTomatoScore and setTomatoScore. When setting tomato score, score is not allowed

    to be negative or over 100.

  •  Write isFresh. A score is considered fresh if it is 60 or above. It is rotten otherwise.

  •  Write display. Print out the name, the total minutes, and if the movie is “Fresh” or “Rotten”.

    Remember, you have method which tells you this now.

  •  The driver is mostly complete. I placed one TODO, add a new movie of your choice to the array

    that stores movies (called myCollection) in the driver.

Your output should match the output below plus the one movie you add to it. Pay attention to how objects are accessed in the driver. See your TA when your output is correct.

Output:
Here are all the movies in my collection of movies.

Movie: Batman The Dark Knight Length: 2hrs 32min.
Tomato Meter: Fresh

Movie: Avengers: Endgame Length: 3hrs 2min. Tomato Meter: Fresh

Movie: The GodFather Length: 2hrs 58min. Tomato Meter: Fresh

Movie: Suicide Squad Length: 2hrs 17min. Tomato Meter: Rotten

//The movie you add will print out here.

_______________________________________________ Here are the Fresh movies.

Batman The Dark Knight is fresh. Avengers: Endgame is fresh.
The GodFather is fresh.

Here are the Rotten movies. Suicide Squad is rotten.

//The movie you add will print out here, it’s score will determine if fresh or not.

_______________________________________________
The movie Harry Potter and the Prisoner of Azkaban was created.

Is Harry Potter and the Prisoner of Azkaban a long movie? Yes, it is a bit long.

Can I set the minutes of Harry Potter and the Prisoner of Azkaban to a negative number?
It did NOT work. Negative runtimes are not allowed.

Can I set tomato score of Harry Potter and the Prisoner of Azkaban to a negative number?
It did NOT work. Negative scores are not allowed.

Can I set tomato score of Harry Potter and the Prisoner of Azkaban to a number greater than 100?
It did NOT work. Still the best Harry Potter movie out all the movies though.

Given Driver

public class MovieDriver {

public static void main (String [] args){

Movie[] myCollection = new Movie[5];

myCollection[0] = new Movie("Batman The Dark Knight", 152, 94);

myCollection[1] = new Movie("Avengers: Endgame", 182, 94);

myCollection[2] = new Movie("The GodFather", 178, 98);

myCollection[3] = new Movie("Suicide Squad", 137, 27);

//TODO

//Initialize the variable below and add it to myCollection at index 4.

//You can pick any movie you wish.

Movie yourMovie;

System.out.println("Here are all the movies in my collection of movies.\n");

for(int i = 0; i < myCollection.length; i++) {

if(myCollection[i] != null) {

myCollection[i].display();

System.out.println();

}

}

System.out.println("_______________________________________________");

System.out.println("\nHere are the Fresh movies.\n");

for(int i = 0; i < myCollection.length; i++) {

if(myCollection[i] != null && myCollection[i].isFresh()) {

System.out.println(myCollection[i].getName() + " is fresh.");

}

}

System.out.println();

System.out.println("Here are the Rotten movies.\n");

for(Movie movieTmp: myCollection){

if (movieTmp != null && !movieTmp.isFresh())

System.out.println(movieTmp.getName() + " is rotten.");

}

System.out.println("_______________________________________________\n");

Movie harryPotter = new Movie("Harry Potter and the Prisoner of Azkaban", 144, 91);

System.out.println("The movie " + harryPotter.getName() + " was created.\n");

System.out.println("Is " + harryPotter.getName() + " a long movie?");

if(harryPotter.getMinutes() > 120) {

System.out.println("Yes, it is a bit long.\n");

} else {

System.out.println("Nope, that isn't too bad.\n");

}

System.out.println("Can I set the minutes of " + harryPotter.getName() + " to a negative number?");

harryPotter.setMinutes(-5);

if(harryPotter.getMinutes() == -5) {

System.out.println("It worked. The runtime is -5 minutes.\n");

} else {

System.out.println("It did NOT work. Negative runtimes are not allowed.\n");

}

System.out.println("Can I set tomato score of " + harryPotter.getName() + " to a negative number?");

harryPotter.setTomatoScore(-100);

if(harryPotter.getTomatoScore() == -100) {

System.out.println("It worked. The score is -100. This movie is terrible according to the site.\n");

} else {

System.out.println("It did NOT work. Negative scores are not allowed.\n");

}

System.out.println("Can I set tomato score of " + harryPotter.getName() + " to a number greater than 100?");

harryPotter.setTomatoScore(101);

if(harryPotter.getTomatoScore() == 101) {

System.out.println("It worked. The score is 101. Best Harry Potter movie ever!\n");

} else {

System.out.println("It did NOT work. Still the best Harry Potter movie out all the movies though.\n");

}

}

}

Solutions

Expert Solution

Please create a file named Movie.java and execute MovieDriver class. Here is the code for Movie class.

public class Movie{
   String movieName;
   int minutes;
   int tomatoScore;
       Movie(String movieName ,int minutes, int tomatoScore){
           setName(movieName);
           setMinutes(minutes);
           setTomatoScore(tomatoScore);
       }
       public String getName() {
           return movieName;
       }

       public void setName(String movieName) {
           this.movieName = movieName;
       }
      
       public int getMinutes() {
           return minutes;
       }

       public void setMinutes(int minutes) {
           if( minutes > 0)
               this.minutes = minutes;
       }
      
       public int getTomatoScore() {
           return tomatoScore;
       }

       public void setTomatoScore(int tomatoScore) {
           if(tomatoScore >= 0 && tomatoScore <= 100)
               this.tomatoScore = tomatoScore;
       }
      
       public boolean isFresh() {
           if(tomatoScore > 60)
               return true;
           else
               return false;
       }
      
       public void display() {
           int hrs = minutes/60 ;
           int mins = minutes - (hrs*60);
           String freshness;
           System.out.print("Movie:"+ movieName);
           System.out.print(" Length:"+ hrs+"hrs"+mins+"min.");
           if(isFresh())
               freshness = "Fresh";
           else
               freshness = "Rotten";
           System.out.print(" Tomato Meter:" + freshness);
       }
}

In the TODO of the movie driver class add a variable for the movie class . For example add the following line.

myCollection[4] = new Movie("Bahubali" ,190 , 99);


Related Solutions

CompSci 251: Intermediate Computer ProgrammingLab 4 – 2019 Introduction For this lab we will be looking...
CompSci 251: Intermediate Computer ProgrammingLab 4 – 2019 Introduction For this lab we will be looking at static, or class variables. Remember, instance variables are associated with a particular instance, where static variables belong to the class. If there are n instances of a class, there are n copies of an instance variable, but exactly one copy of a static variable. Underlined items are static members of the class. The lab also uses enums to control what is an acceptable...
Introduction This lab will focus on creating a Movie class conforming to the diagram above. From...
Introduction This lab will focus on creating a Movie class conforming to the diagram above. From this class Movie objects can be instantiated and used in a running program. I have provided a mostly completely driver, you will need to add a few lines of code where specified. What you need to do  Declare you instance variables at the top of the class.  Write a specifying constructor. No default constructor is required.  Write getName and setName. There...
CompSci 251 Assignment 1 Due Sep. 23rd, 2019 Create a program that will format long pieces...
CompSci 251 Assignment 1 Due Sep. 23rd, 2019 Create a program that will format long pieces of text based on user input. User input will determine the number of indents allowed for the first line in each paragraph, the number of characters allowed per line, and the number of sentences allowed per paragraph. There are three pieces of text, where each is a famous speech that is represented by a single String variable at the top of the base file....
CompSci 251: Assignment 3 Due 2/20, 2017 10:00am Topics Covered: Instance variables and methods; using a...
CompSci 251: Assignment 3 Due 2/20, 2017 10:00am Topics Covered: Instance variables and methods; using a driver class 1 Introduction This assignment will have you implement your first real Java class using instance variables(state) and meth- ods(behaviour). It will also probably be the first time that you write a program with a driver class. 2 Income tax computation Most Americans (not just Americans, really!) complain about filing their income taxes. Some people dont think they should pay at all. Others...
This lab will focus on creating a better understanding of Selection Sort and Insertion Sort algorithms....
This lab will focus on creating a better understanding of Selection Sort and Insertion Sort algorithms. What you need to do I have provided a driver and a Utility class with three methods. You must finish writing Selection Sort and Insertion Sort in the Utility class. Below is pseudocode for Selection and Insertion Sort, which you may use as a guide. Your selection sort will sort an array of Strings lexicographically, meaning A-Z. Your insertion sort will sort an array...
Creating a Database Design Lab 1: Creating a Database Design (Wk 3) - OR - Draw...
Creating a Database Design Lab 1: Creating a Database Design (Wk 3) - OR - Draw with pencil and paper diagram (take photo of it and submit) along with a summary of the diagram you prepared in a Word document. Use the scenario from Assignment 1: Business Rules and Data Models to complete the lab: Suppose a local college has tasked you to develop a database that will keep track of students and the courses that they have taken. In...
This is Python programming Focus 1. Classes and Objects 2. Creating objects 3. Manipulating objects This...
This is Python programming Focus 1. Classes and Objects 2. Creating objects 3. Manipulating objects This lab maps to learning the following objectives: Write a working program that creates a Class, Instances of Objects from that Class, and Functions that use Objects as parameters. For this portion of the lab, you will create a new program for your Professor. Create a class named Student that holds the following data about a student: 1. Name 2. Student ID number 3. GPA...
Question 3 Identify and describe a minimum of four internal controls in a computer lab classroom....
Question 3 Identify and describe a minimum of four internal controls in a computer lab classroom. Required Classify each control as being preventive, corrective and/or detective. If the control is an information technology control, also classify the control as a general or application control. Describe the risk(s) each control is intended to address. Describe the operation of each control. Identify and discuss a potential deficiency in at least one of the controls you have identified.
Construct a graph from Tables 2 and 3 on a computer program such as Microsoft Excel®. Send your graph with your Post-Lab Questions to your lab instructor.
  Table 1: Hot Sauce Titration mass of hotsauce (g) 0.8 Concentration of NaOH solution used 0.1M Volume needed of NaOH to neutralize the sauce_______? pH of NaOH 12.5 Table 2: Hot Sauce pH Titration Data Trial 1 Increments of NaOH Added (mL) Total NaOH Added (mL) Hot Sauce pH 0 0 3.7 1.0 1.0 4.1 1.0 2.0 4.4 1.0 3.0 4.8 1.0 4.0 5.6 1.0 5.0 9.7 1.0 6.0 11.2 1.0 7.0 11.5 1.0 8.0 11.7 1.0 9.0 11.9...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT