Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Instructions ( a ) Add the following private instance variables to the Movie class: An instance variable called title of type String. An instance variable
Instructions
a Add the following private instance variables to the Movie class:
An instance variable called title of type String.
An instance variable called director of type String.
An instance variable called year of type int.
b Add the following methods to the Movie class:
A void method called initialize that takes two Strings and an int
as arguments, and uses those arguments to set the values of the title,
director, year instance variables.
A void method called display that displays the title and director of the
movie followed by the year in parentheses. For example, if the title of the
movie is Blade Runner, the director is Ridley Scott and the year is
it should display Blade Runner dir. Ridley Scott
Accessor methods getters for each instance variable.
Mutator methods setters for each instance variable.
c In the main function of your main class, remove the line that prints Hello
World to the output screen and then create a Movie object and perform the
following unit tests:
Initialize the movie object with a title, director and year of your choice,
and display it Your output might look like this:
Testing initialize and display:
Blade Runner dir. Ridley Scott
For each instance variable use the corresponding mutator to change the
value, then use the accessor to make sure that the value changed. Your
output for getTitle and setTitle might look like this:
Testing setTitle and getTitle:
getTitle returns: Blade Runner
calling setTitle with argument: Brazil
getTitle returns: Brazil
d Run the main program to see if the tests were successful.
e Add an equals method to the Movie class that takes a Movie object as anargument and returns true if the argument has the same title, director, and
year as the current object. Remember to use the equals method of the String class to compare the two titles.
f Add code in your main method in your main class that performs the following unit tests:
Create two movies with different titles, but the same director and year,
and test if they are the same using equals. Your output might look like
this:
Testing equals on different titles, same director and
year
The Wasp Woman dir. Roger Corman
A Bucket of Blood dir. Roger Corman
equals returns false
Create two movies with the same title and director, but different years
and test if they are the same using equals. Your output might look like
this:
Testing equals on different years, same title and
director
Halloween dir. John Carpenter
Halloween dir. John Carpenter
equals returns false
Create two movies with the same title, director, and year, and test to see
if they are the same using both and equals. Your output might look
like this:
Testing equals and on objects with the same data
Suspiria dir. Dario Argento
Suspiria dir. Dario Argento
equals returns true
returns false
Declare a variable of type Movie and set it equal to one of the previous
Movie objects you created. Compare the new variable and the one you
set it equal to using both and equals Your output might look like
this:
Testing equals and on references to the same object
Phantasm dir. Don Coscarelli
Phantasm dir. Don Coscarelli
equals returns true
returns true
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started