4-

1. Purchase Program(Savitch, page 294, problem 6). Teacher's Note: the Purchase.java program located on your CD and (possibly) listed in the book are slightly incorrect. A corrected version of the program(which you will need for this assignment) is located on this website in the handouts sections and has a link to it in the next sentence. Write a program that uses the Purchase class(similar to Display 4.11, page 253, but corrected here) to set the following prices:

Oranges: 10 for 2.99

Eggs: 12 for 1.69

Apples: 3 for 1.00

Watermelons: 4.39 each

Bagels: 6 for 3.50

and calculate the total bill and subtotals for each item for the following:

two dozen oranges,

three dozen eggs,

twenty apples,

two watermelons, and

a dozen bagels.

 

2. Modify Triangle. For this problem you will need the Triangle class located here. The Triangle class currently has numerous functions for setting the base and height of the triangle and for getting these values back. Unfortunately, the author didn't include a way to get the area of any Triangle objects. Modify the Triangle class to include the following function:

double getArea() - The method returns the size of the Triangle's area as a double. The area of a triangle can be calculated by 0.5*base*height.

Make a test program to test all of the functionality of the new Triangle class. Create a Triangle with a base of 3 and a height of 5. Have your program then output the base, the height, and the area. An example output might be something like this:

The triangle with a base of 4.0 and a height of 5.0 has an area of 10.0