Question

Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the...

Java only please

  1. Write a program that displays the following menu:

Geometry Calculator

1.       Calculate the Area of a Circle

2.       Calculate the Area of a Triangle

3.     Calculate the Area of a Rectangle

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 formula:      area = ∏r2    Use 3.14159 for ∏.

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

If the user enters 3, the program should ask for the length and width of the rectangle of the rectangle and then display the rectangle’s area. Use the formula:   area = length * width. Also display a message if the figure is a square.

If the user enters 4, the program should end.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class GeometryCalculator {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double radius, length, width, base, height;
        while (true) {
            System.out.print("" +
                    "    Geometry Calculator\n" +
                    "        1.  Calculate the Area of a Circle\n" +
                    "        2.  Calculate the Area of a Triangle\n" +
                    "        3.  Calculate the Area of a Rectangle\n" +
                    "        4.  Quit\n" +
                    "Enter your choice (1-4): ");
            int choice = in.nextInt();
            switch (choice) {
                case 1:
                    System.out.print("Enter radius of circle: ");
                    radius = in.nextDouble();
                    System.out.println("Area of circle is " + (Math.PI * radius * radius));
                    break;
                case 2:
                    System.out.print("Enter base of triangle: ");
                    base = in.nextDouble();
                    System.out.print("Enter height of triangle: ");
                    height = in.nextDouble();
                    System.out.println("Area of triangle is " + (0.5 * base * height));
                    break;
                case 3:
                    System.out.print("Enter length of rectangle: ");
                    length = in.nextDouble();
                    System.out.print("Enter width of rectangle: ");
                    width = in.nextDouble();
                    System.out.println("Area of rectangle is " + (length * width));
                    break;
                case 4:
                    return;
                default:
                    System.out.println("Invalid choice. Try again!");
                    break;
            }
            System.out.println();
        }
    }
}

Add a comment
Know the answer?
Add Answer to:
Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator...

    (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code 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): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...

  • Geometric calclator use python to do this program. Write a program that displays the following menu:...

    Geometric calclator use python to do this program. Write a program that displays the following menu: 1. Calculate the area of circle 2. calculate the area of rectangle 3. calculate the area of triangle 4. Quit Enter your choice (1-4). if the user enters 1, your program should ask for the radius of the circle and then display its area. Use the formula to calculate the circle's area: Area = pi*r^2 Use 3.14149 for Pi and the radius of the...

  • Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects....

    Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- rectangle 2 -- circle 3 -- triangle 4 -- quit If the user selects choice 1, the program should find the area of a rectangle. rectangle area = length * width If the user selects choice 2, the program should find the area of a circle. circle area = PI * radius * radius...

  • Menu-driven programs will display the menu options to the user and then prompt them for a...

    Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...

  • Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape...

    Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape from the information supplied. Write pseudocode to solve this problem and write a Python program that asks the user to input the required information for a shape and then calculates the area of the shape. 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...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • Using C++, Write a program that will provide the user a menu from which the user...

    Using C++, Write a program that will provide the user a menu from which the user may select to calculate the area of one of four geometric shapes: a circle, a rectangle, a triangle, and a trapezoid. You should use the most appropriate SWITCH block for this program. The user will input all data needed to calculate the area. The program should output all data input by the user, the calculated area, and the geometric shape selected. Run this program...

  • Q2: Write a menu-driven C program using switch-case to calculate the following: 1. Area of circle...

    Q2: Write a menu-driven C program using switch-case to calculate the following: 1. Area of circle 2. Area of square 3. Area of rectangle The program should use the following functions properly: void displayMenu() //a function that will display the menu options to the user int getChoice() //a function that will input the user choice and returns it float calculate(int choice) //a function that reads the required inputs based on the user choice, and returns the area of the shape...

  • Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class...

    Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class should have a zero-argument constructor that initializes each data member to 0. It should have member functions named calcPerimeter() and calcArea() that calculate the perimeter and area of a rectangle respectively, a member function setLength() and setWidth() to set the length and width, member functions getLength() and getWidth() to return the length and width, and a member function showData() that displays the rectangle’s length,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT