The assignment can be handed in earlier at Carpenter.
Type your name, id number, section number, and
section day/time/instructor in a comment at the top of your
assignment.
Table of Contents
What to do for this assignment
Overview. This program develops Java classes that let you simulate a small database of movie reviews. You will create one general class that gives a few properties of all movies and then create two movie subclasses, one for good movies and one for bad movies. You will define:
Details. (0) Start a new project in CodeWarrior, using stationery CUCS Java Application. Erase all the statements in the body of method main.
(1) Create a new file, save it as Movie.java, and add it to the project (using, say, menu item Project | Add Window). Move it to the Sources folder in the project window. In Movie.java, write a public class Movie with the following components:
(2) Define a public static method describe within class CUCSApplication. Copy and paste or type in the following code:
// Print the description (using
toString) and review (using showReview) of a Movie
public
static void describe(Movie m)
{ System.out.println(m.toString()); // print general movie description
m.showReview(); // display the review
System.out.println("\n");
}
If you're running on a PC (rather than a Mac) you'll need to add the
following code to the end of the main method. This code simply
keeps the output window from disappearing.
try {
System.in.read(); // prevent console window from going away
} catch (java.io.IOException e) {}
Test all of this out by creating an instance of class Movie in CUCSApplication.main and calling method describe with the instance as the argument. You should see the movie name and year of the movie that you provided via Movie.toString and the error message you provided via Movie.showReview.
(3) Create two subclasses of class Movie, ThumbsUp (for good movies) and ThumbsDown (for bad movies). These can be defined in Movie.java. No new fields need to be created in the subclasses. You will have to implement a constructor for each. Each constructor should have three parameters: a String with which to initialize the name field; an int parameter with which to initialize the year field; and a String parameter with which to initialize the notes field. The constructors should call super to initialize fields name and year; after that, they should initialize the notes field with the third parameter. Since the toString method for the Movie class still applies to the subclasses, do not define a toString method for the subclasses --- the subclasses will inherit the toString method from the parent class. You will have to define a showReview method for each subclass. Use the specifications in section 1f above. Just in case it's not already obvious, the ThumbsUp summary line should indicate that the movie was good; the ThumbsDown summary line should indicate that the movie was bad.
(4) When everything is working, change method CUCSApplication.main so that it creates an instance of each of your subclasses of Movie and describe (by calling method describe) each instance.
Remember to place meaningful comments in your code, and
also include your name, id number, section number and section
day/time/instructor in the first comments at the top of the
program. Note that you can use method describe for the
subclasses --you do not have to write a version for every single
(sub)class.
What to hand in:
(a) The final version of classes
CUCSApplication, Movie, and its two subclasses
--including all attendant methods. Method main of
Application should create instances of the two subclasses and
describe them; it should do no more and no less. At the top of the
page should be your name, id, section number and section
day/time/instructor.
(b) Output from running your code.