CS 1401, Exam #4

Date: Wednesday, November 22, 2006, 11:30 am
Name (please type legibly, ideally in block letters): ______________________________________________________________________

1. Define a class Pie in which each object has two parameters: weight of the pie (in ounces), and the number of people served (both integers). Do not forget to include a constructor method, accessor methods, mutator methods, and a method that computes the (integer-valued) amount per person served.

















































2. Considering the class Pie (defined in Problem 1) as a superclass, define a subclass PumpkinPie in which each object has an additional field: the weight of the frosting. Overwrite the original amount-per-person method: it should now divide the total weight of the pie and of the frosting by the number of persons served.
























































3. In the main method, define a new object of type PumpkinPie (as defined in Problem 2). This object should describe a pumpkin pie that weighs 20 ounces, has 5 ounces of frosting, and serves 5 persons. Use the amount-per-person method to compute and print the amount per person served.

























































4. Trace your code from Problem 3 step-by-step.


























































5. Modify the amount-per-person method from Problem 2 as follows: use try/catch block to produce a meaningful error message when the number of persons served is 0.

























































6. Write a method that, given an array h of integers, computes the largest element of this array. Test your method step-by-step on a numerical example.