# Program 2 – Write a program titled “YourLastName_Geometry” Solution

20.00 \$ 10.00 \$

Category:

## Description

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 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