Program 2 - Write a program titled "YourLastName_Geometry" Solution

Write a program titled "YourLastName_Geometry" which has the following methods:
 A static method that accepts the radius of a circle and returns the area of the circle.
Use the following formula: Area = πr2
Use Math.PI for π and the radius of the circle for r.
 A static method that accepts the length and width of a rectangle and returns the area
of the rectangle. Use the following formula: Area = Length x Width
 A static method that accepts the length of a triangle's base and the triangle's height.
The method should return the area of the triangle. Use the following formula:
Area = Base x Height x 0.5
The methods should display an error message if negative values are used for the circle's
radius, the rectangle's length or width, or the triangle's base or height.
Next, write a driver program titled "YourLastName_Driver" to test the geometry class. The following shows an
example interaction of the driver and geometry classes captured in a file by the command “% script Driver.out”
(bolded areas represent the user's input):
Script started on Thu Sep 26 10:23:58 2013
% java Diaz_Driver
Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Enter your choice (1-4): 1
Enter the radius of the circle: 9
The area of the circle is: 254.47
Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Enter your choice (1-4): 4
% exit
script done on Thu Sep 26 10:24:17 2013
Display an error message if the user enters a number outside the range of 1 through 4 when
selecting an item from the menu.
Run the program with different inputs and capture all interaction in a file using the script command.
What to turn in:
- Soft copy of the script command (using Blackboard)
- Soft copy of the program (submit your .java file using Blackboard)
Powered by