Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me please , This is for COSC 1336 : please see the following qu

ID: 3727885 • Letter: C

Question

Can someone help me please , This is for COSC 1336 : please see the following question

  

Geometry Calculator

Write a program that displays the following menu:


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


If the user enters 1, the program should ask for the radius of

the circle and then display its area. Use the following formula:

area = (the square of r)

Use 3.14159 for and the radius of the circle for r.

If the user enters 2, the program should ask for the length and
width of the rectangle and then display the rectangle’s area.
Use the following formula:

area = length * width

If the user enters 3, the program should ask for the length of
the triangle’s base and its height, and then display its area.
Use the following formula:

area = base * height * .5

If the user enters 4, the program should end.

Input Validation: Display an error message if the user enters a
number outside the range of 1 through 4 when selecting an item
from the menu. Do not accept negative values for the circle’s
radius, the rectangle’s length or width, or the triangle’s base
or height.

NOTE:
If the user enters an improper menu choice (1-4), the program prints
"The valid choices are 1 through 4. Run the program again and select one of those."


If the user enters a negative radius, the program prints "The radius can not be less than zero."


If the user enters a negative value for height or base , the program prints "Only enter positive values for base and height."

Input Validation: Do not accept a number less than 1 or greater than 10.

Explanation / Answer

Diaz_Driver.java

import java.util.Scanner;

public class Diaz_Driver {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Geometry Calculator");

System.out.println("1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit");

System.out.println("Enter your choice (1-4): ");

int choice = scan.nextInt();

double area;

while(choice != 4){

switch(choice) {

case 1: System.out.println("Please enter the radius of Circle");

double radius = scan.nextDouble();

if(radius<=0) {

System.out.println("The radius can not be less than zero.");

} else {

area = getCircleArea(radius);

System.out.println("The area of the Circle is: "+area);

}

break;

case 2:

System.out.println("Please enter the length of Rectangle");

double length = scan.nextDouble();

System.out.println("Please enter the width of Rectangle");

double width = scan.nextDouble();

if(length<=0 || width<=0) {

System.out.println("Only enter positive values for length and width");

} else {

area = getRectangleArea(length, width);

System.out.println("The area of the Rectangle is: "+area);

}

break;

case 3:

System.out.println("Please enter the base of Triangle");

double base = scan.nextDouble();

System.out.println("Please enter the height of Triangle");

double height = scan.nextDouble();

if(base<=0||height<=0) {

System.out.println("Only enter positive values for base and height");

} else {

area = getTriangleArea(base, height);

System.out.println("The area of the Rectangle is: "+area);

}

case 4:

System.out.println("Exit");

break;

default:

System.out.println("Error: The range should be between 1 and 4");

}

System.out.println("1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit");

System.out.println("Enter your choice (1-4): ");

choice = scan.nextInt();

}

}

public static double getCircleArea(double radius){

return 2 * Math.PI * radius;

}

public static double getRectangleArea(double length, double width){

return length * width;

}

public static double getTriangleArea(double base, double height){

return base * height * 0.5;

}

}

Output:

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
Please enter the radius of Circle
2
The area of the Circle is: 12.566370614359172
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):
3
Please enter the base of Triangle
4
Please enter the height of Triangle
5
The area of the Rectangle is: 10.0
Exit
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):
3
Please enter the base of Triangle
6
Please enter the height of Triangle
2
The area of the Rectangle is: 6.0
Exit
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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote