Question

In: Computer Science

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 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.

Solutions

Expert Solution

Movie.java

public class Movie{

    public String movieName;
    public int tomatoScore;
    public int minutes;

    public Movie(String mName,int tScore,int min){
        movieName = mName;
        tomatoScore = tScore;
        minutes = min;
    }

    public void setName(String mName){
        movieName = mName;
    }

    public String getName(){
        return movieName;
    }

    public void setTomatoScore(int tScore){
        if(tScore < 0){
            System.out.println("Tomato Score cannot be negative");
            return;
        }
        if(tScore > 100){
            System.out.println("Tomato Score cannot be greater than 100");
        }
        tomatoScore = tScore;
    }

    public int getTomatoScore(){
        return tomatoScore;
    }

    public void setMinutes(int min){
        if(min < 0){
            System.out.println("Running time cannot be negative");
            return;
        }
        minutes = min;
    }

    public int getMinutes(){
        return minutes;
    }

    public boolean isFresh(){
        if(tomatoScore >= 60){
            return true;
        }
        else
            return false;
    }

    public int getHours(){
        return minutes/60;
    }

    public String runningTime(){
        int hrs = getHours();
        int min = minutes - (60 * hrs);
        String time = "" + hrs + "hrs " + min + "min.";
        return time;
    }

    public void display(){
        String time = runningTime();
        String freshness;
        if(isFresh()){
            freshness = "Fresh";
        }
        else{
            freshness = "Rotten";
        }
        System.out.println("Movie: " + movieName + " Length: " + runningTime() + " Tomato Meter: " + freshness);
    }
}

MovieTester.java

public class MovieTester {

    public static void main(String... args){
        Movie movie = new Movie("myMovie",75,200);
        movie.display();
        movie.setTomatoScore(200);
    }

}

Output:

I could not provide you the exact way that you require because you haven't provided any details about the diagram and the driver code.

But I hope the functions that I have given you will help.

Please appreciate the solution if you find it helpful.

If you have any doubts in the solution, feel free to ask me in the comment section.


Related Solutions

In C++ In this lab we will be creating a stack class and a queue class,...
In C++ In this lab we will be creating a stack class and a queue class, both with a hybrid method combining linked list and arrays in addition to the Stack methods(push, pop, peek, isEmpty, size, print) and Queue methods (enqueue, deque, peek, isEmpty, size, print). DO NOT USE ANY LIBRARY, implement each method from scratch. Both the Stack and Queue classes should be generic classes. Don't forget to comment your code.
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
We started creating a Java class for Car. In this lab we are going to complete...
We started creating a Java class for Car. In this lab we are going to complete it in the following steps: 1- First create the Car class with some required instance variables, such make, model, year, price, speed, maxSpeed, isOn, isMoving, and any other properties you like to add. 2- Provide couple of constructors for initializing different set of important properties, such as make, model, year, and price. Make sure that you do not repeat initialization of instance variables in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
Real-World Focus The Coca-Cola Company hardly needs an introduction. A line taken from the cover of...
Real-World Focus The Coca-Cola Company hardly needs an introduction. A line taken from the cover of a recent annual report says it all: If you measured time in servings of Coca-Cola, “a billion Coca-Cola's ago was yesterday morning.” On average, every U.S. citizen drinks 363 8-ounce servings of Coca-Cola products each year. Coca-Cola's primary line of business is the making and selling of syrup to bottlers. These bottlers then sell the finished bottles and cans of Coca-Cola to the consumer....
i need a good introduction for a lab report about (isolation of caffeine from No-Doz tablets)...
i need a good introduction for a lab report about (isolation of caffeine from No-Doz tablets) . i am really not good at writing introduction and councluion. for introduction i only wrote ( The purpose of this experiment was to extract the caffeine from a No-Doz tablets by recrystallizing it.) please help!!
Lab Exercise 10 - ISOLATION OF DNA FROM PLANTS Introduction Deoxyribonucleic acid (DNA) is located in...
Lab Exercise 10 - ISOLATION OF DNA FROM PLANTS Introduction Deoxyribonucleic acid (DNA) is located in the nucleus of eukaryotic cells (animals, plants, fungi, and protists). DNA contains information to direct the cell in the manufacture of proteins. Proteins control development, organ function, metabolism, enzymatic reactions, photosynthesis, muscle action, brain activity, and many other cellular processes. DNA is often referred to as the “blueprint for life”. DNA is a polymer composed of the nucleotide bases guanine (G), adenine (A), thymine...
An instructor from the school of business samples the students in his introduction to business class...
An instructor from the school of business samples the students in his introduction to business class to learn about the amount of dollars students spend per semester on textbooks. The distribution that follows indicates the results of his sample. SHOW WORK. Textbook Costs per Student per Semester (in dollars) 65, 147, 171, 142, 153, 187, 195, 106, 127, 178, 178, 205, 175, 178, 133, 186, 55 a) Construct a Box-and-Whisker Plot b) Calculate the interquartile range c) Determine if there...
In this lab you will learn how to use methods from the Math class in order...
In this lab you will learn how to use methods from the Math class in order to calculate the area or the volume of several different shapes. If you are confused about the Methods you can access from the Math class and would like to see some examples click here. Hint: Most of these methods can be done in one line. Step 1 - circleArea In this method you will calculate the area of a circle. Before you can calculate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT