Part of your grade will depend on your methods having suitable specifications and your fields having suitable definitions. Write a method specification before you write a method. Write a field definition at the time you declare the field
Submit your program electronically before the deadline.
You will write the program from scratch. Start by constructing a new folder, say tvshow.
You will write Java classes that let you simulate a small database of TV-show
reviews. You will create one general class that gives a few properties of all
TV shows and then create two subclasses, one for good shows and one for bad
shows. You will define:
Suggestion: Develop your program incrementally. Do it in small steps,
roughly as suggested above, rather than try to do everything at once. By testing
as you go, you have fewer things to worry about and can avoid repeating mistakes.
Also, use the class names and names of public components that are given to you
in this document we need those for our automatic testing program to test
your program. Copy and paste is the best way to go.
In DrJava, create a new file, place in it a public class TVShow, and save it as TVShow.java in folder tvshow. Compile the program to make sure there are no mistakes.
Add the following components to class TVShow, checking after each addition that the program still compiles. Be sure to write the specification of a method before writing the method body. Be sure to annotate each instance variable with a comment that gives its meaning.
After each addition, check that your syntax is ok by compiling the program and use the DrJava Interactions pane to make sure your methods work correctly.
No new fields need to be created in the subclasses, but each needs a three-parameter constructor. The parameters are, in this order: a String with which to initializethe name of the show, an int with which to initialize the year, and a String with which to initialize the notes.
The only other method to define in each subclass is method showReview. In class ThumbsUp, method showReview should return a String consisting of two lines (use "\n"): a summary line that says something like
"<name of show> was a Great Show! "
and a second line that contains the notes that were entered for it in the constructor, e.g. "Full of laughs!" or "Judge Judy is great!". In class ThumbsDown, the summary line should say "<name of show> was the pits."
Note that all good shows have the same summary line, as do all bad shows.
Do whatever you have to do, using the interactions pane, to make sure your subclasses are correct.
Place in class ThumbsUp the following static method.
/** Print the description (using toString) and review (using showReview) of
a show s */
public static void describe(TVShow s) {
System.out.println(s.toString());
System.out.println(s.showReview());
System.out.println( " \n " );
}
Note: When we copied and pasted and tried to compile, we got an error message that said something like "Error, illegal character". If you get this, copy and paste one line at a time, or type the method into the class.
Check out this method, using the interactions pane, by (1) creating instances of the three classes and (2) calling this method several times with each instance as the argument.
Even though procedure describe is in class ThumbsUp, when called with an argument of class ThumbsDown it prints a thumbs-down report. Why is this? Under the method, write, as a comment, a detailed explanation of why this is. For example, state what happens to an argument p in a call ThumbsUp.describe(p) as it is passed to the procedure and how it is handled inside the procedure body. This explanation of your is important, so be as clear and precise as you can.