Name(s) & ID(s):_________________________________________________________

Assignment P2

CS 100 � Summer 1999

Due: Thursday July 15, 1999 at the beginning of class.

Turn in your assignments according to the instructions given in the first day handout. Remember to include sample output when you turn in your program listings. Also turn in a disk with a runnable version of your code (the same as what you've printed). You are allowed to work with one partner on this assignment. Each problem is worth 20 points. Remember that you will be graded on both style and correctness. For the written problem, please turn in typed (or highly legible handwriting) responses.

Problem 1 -- In this problem you will develop Java classes to simulate a small database of book reviews. You should create one general class that gives a few general properties of all books and then you should create two book subclasses one for "literary" books and one for "trashy" books. You should define:

Both the superclass Book and the subclasses Literary and Trashy should have a method showReview. The showReview method in the superclass should just print an error message, since objects of class Book are unreviewed. The showReview method in the subclasses should print two things to System.out: (1) a summary line that indicates whether the book was good or bad (e.g., "This was a SPLENDID piece of literature!"), and (2) the reviewer's notes (e.g., "Reviewer's notes: Intricate plot, superb characterization"). The superclass and subclasses should have appropriate constructors.

Your task is to implement these classes as described and write a main method that will demonstrate that all of your classes work appropriately. So, main should create several objects of type Book, some of which are Literary and some of which are Trashy. The final output on running your program should be a list of titles along with corresponding summary lines and reviewer's notes.

Problem 2 -- A gym offers two different types of membership: Fit and Flab. To distinguish a Fit membership from a Flab membership, the Fit memberships are numbered from 000001, and Flab memberships are numbered from 500,000. Every time a new membership is opened, the system should generate a new unique membership number.

Fit accounts charge $250/year, provided the member comes to the gym at least 4 times per week, otherwise the Fit membership requires an additional $20/month. Fit memberships offer a 25% discount when buying items at the gym's yogurt bar.

Flab memberships charge $100/year provided the member comes to the gym less than 3 times per week, otherwise the Flab membership requires an additional $25/month. Flab members pay full price at the gym's yogurt bar.

Devise appropriate classes for the different types of memberships. Include methods that you think appropriate for access and manipulation of data in a member's account.

Write a test program to verify that the classes have been implemented correctly.

 

Problem 3 -- (Similar to problem 4.19 in text): Write a class called Triangle that can be used to represent a triangle. It should include the following methods that return boolean values indicating if the particular property holds (along with constructor(s) and appropriate fields):

Then, write a method main that demonstrates that your class is working properly. Your program should query the user for the integer lengths of the sides of a triangle and then output whatever information can be determined about the triangle using the methods described above. E.g., your output might look something like:

What is the length of the first side of your triangle? 5

What is the length of the second side of your triangle? 3

What is the length of the third side of your triangle? 4

Pondering. . . . . Your triangle is a right triangle!

Problem 4 -- Write a program that requests and accepts a series of positive numbers as input from the user (where you do not know the number of numbers in advance -- assume that input of 0 indicates the end of the list), print their arithmetic mean, the maximum number and the minimum number.

Problem 5 -- (written answers only)