CS100A Fall 1998 Assignment 3
Due at the beginning of class on Tuesday, October 6

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

0. Working with others. For this assignment, you may work with one other person. If you do, then you must actually do the work together; sit at a computer together, and make changes together. It is not proper for one person to do the work and then to add someone else's name to it. If you work with someone else, then hand in only one assignment; put both persons' names and ids on it.

The goals of this assignment:

The program that you will modify: You will write the program almost from scratch. When you use the CUCS Java Application stationery,  it will create a default file CUCSApplication.java. Modify this file as necessary, but be sure to delete ALL extraneous code AND comments. (CUCS Java GraphicsApplication can also be used but is unnecessary because this assignment has no graphics.)

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:

Suggestion. Develop your program incrementally: do it in small steps, roughly as suggested above, rather than trying to do everything at once. By testing as you go along, you have fewer things to worry about and can avoid repeating mistakes.

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:

Check that your syntax is ok by selecting menu item Project | Run or Project | Check Syntax. A more extensive test is done in the next part.

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