*Please i need help with this homework it is java* The solution you developed fo
ID: 3829293 • Letter: #
Question
*Please i need help with this homework it is java*
The solution you developed for .... found the area and perimeter for the four shapes we have investigated so far, but what if the user wanted to find those properties for a single shape rather than all four? The solution developed in ..... can be visually confusing (not to mention annoying if the user was indeed interested in only a single shape). Modify your solution for .... to allow the user to choose the shape to compute and report. Changing the "look and feel" of the program enhance the user experience by allowing her/him to focus on the information needed. There are several selection structure implementations (if-else, switch) that can be used in the solution. The user should be provided with a "menu of choices" that will allow them to identify the shape they wish to work with. A typical session might look like this:
Choose the shape
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
Enter your choice: 1
Enter the side (as a decimal): 10.5
The area is 110.25
The perimeter is: 42.0
Thank you
Procedure:
Move it into Eclipse and begin the necessary modifications.
Add the comment // modified by: ... and supply your name and the current date.
Save the program with the file name .... where xx are your initials. Be sure to change the class name to this as well (to avoid the run-time error "class not found" message).
Modify the program as indicated in the Problem Statement above.
Compile the program and correct any syntax errors detected by the compiler.
When the syntax errors have been corrected, test the program in Eclipe. Before testing, on paper, create test data and perform the computations manually. These will serve as your control for testing.
Compare the results produced by your program with your hand derived results.
Using the commenting facility, put your test data at the end of the program file.
Submit the source program file through this Canvas dropbox for evaluation, feedback and credit.
Notes:
Use the same "prompt and respond" dialog from your version of ..... to collect the data and report the results for each of the other three shapes. A refresher:
Should the user choose the rectangle (2):
Enter the first side (as a decimal): 10.5
Enter the second side (as a decimal): 15.5
The area is 162.75
The perimeter is: 52.0
Should the user choose the circle (3)
Enter the radius (decimal): 30.2
The area is: 2,865.2557
The circumference is: 189.752
Should the user choose the triangle:
Enter the height of the triangle (decimal): 3.0
Enter the base of the triangle (decimal): 4.0
The area is: 6.0
The perimeter is 12.0
When deciding on the data type to use for your sides (rectangle), radius (circle), base and height (triangle) consider how you will use them and the numeric types that will be used in the computations.
Declare PI as a named constant (preferably of the type double) and assign it the value of 3.14159 at the time of declaration.
Notice that the example above strongly suggests that your program will require a series of interactions with the user in order to gather data for each set of shape calculations.
Assume you will be working with a right triangle (a triangle of 90 degrees).
Some calculations you may find useful:
for the perimeter of a rectangle:
perimeter = 2 * (side1 + side2)
for the circumference of a circle:
circumference = 2 * PI * radius
for the perimeter of a triangle:
perimeter = base + height + hypotenuse
to find the hypotenuse of the right triangle:
hyptenuse2 = base2 + height2
Explanation / Answer
Hi, Please find my implementation.
Please let me know in case of any issue.
import java.util.Scanner;
public class GeometricAreaPerimeterCalc {
/**
* this methods show the list of choice
*/
public static void printMenu(){
System.out.println("1. Square");
System.out.println("2. Rectangle");
System.out.println("3. Circle");
System.out.println("4. Triangle");
System.out.println("5. Quit");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int c;
while(true){
printMenu();
c = sc.nextInt();
if(c == 5)
break;
if(c == 3){
System.out.print("Enter radius: ");
double radius = sc.nextDouble();
double area = 3.14*radius*radius;
double perimeter = 2*3.14*radius;
System.out.printf("Area of circle = %.2f ",area);
System.out.printf("Perimeter of circle = %.2f ",perimeter);
}
else if(c == 4){
System.out.print("Enter base: ");
double base = sc.nextDouble();
System.out.print("Enter height: ");
double height = sc.nextDouble();
double area = 0.5*base*height;
double hyp = Math.sqrt(base*base + height*height);
double perimeter = height + base + hyp;
System.out.printf("Area of triangle %.2f ",area);
System.out.printf("Perimeter of triangle %.2f ",perimeter);
}
else if(c == 2){
System.out.print("Enter width: ");
double width = sc.nextDouble();
System.out.print("Enter height: ");
double height = sc.nextDouble();
double area = width*height;
System.out.printf("Area of rectangle = %.2f ",area);
System.out.printf("Perimeter of rectangle = %.2f ",(2*(width + height)));
}
else if(c == 1){
System.out.print("Enter side: ");
double side = sc.nextDouble();
double area = side*side;
System.out.printf("Area of square = %.2f ",area);
System.out.printf("Perimeter of square = %.2f ",4*side);
}
else
System.out.println("Invalid characcter!!");
}
}
}
/*
Sample run:
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
1
Enter side: 4
Area of square = 16.00
Perimeter of square = 16.00
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
3
Enter radius: 4.5
Area of circle = 63.59
Perimeter of circle = 28.26
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
5
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.