Find Us On:

# Java - Geometry Calculator

julesxdujour

Design a Geometry class with the following methods: - A static metod that accepts the radius of a circle and returns the ares f the circle. use the following formula. Area=πr^2 The math.PI for Area=π 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 follow forumula. Area = length x width - A statuc method that accepts the length of a triangle's base and the triangles 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 circles radius, the rectangle's length or width, or the triangle's base or height. Next write a program to test the class, which displays the following menu and responds to the user's selection: Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Are of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter you choice (1-4): Display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. Turn in the Java source code (.java) files Geometry.java and GeometryCalc.java Attachments
Tags Clarifications

## Geometry Calculator - Java

dickersonka

Attached is the geometry calculator source including comments with eclipse project Attachments
GeometryCalculator.zip (4 K)

Preview
* width; } /** * Area of triangle * @param base base * @param height height * @return area */ public static double areaOfTriangle(double base, double height){ //Validate non negative if(base < 0 || height < 0){ //Print

Preview
break; case 3: //Triangle //Prompt for base and height System.out.print("Enter base: "); double base = scanner.nextDouble(); System.out.print("Enter height: "); double height = scanner.nextDouble(); //Calculate triangle area area = Geometry.areaOfTriangle(base, height); break; case 4: //User chose to exit

Screenshots