Question

In: Computer Science

/* calculating area of a circle, calculating area of a rectangle, calculating area of a triangle,...

/*
calculating area of a circle, calculating area of a rectangle, calculating area of a triangle, and quit.
*/


import java.util.Scanner;
public class GeoCalculator
{
  
public static void main(String arg[])
{

int geoCalc; //number selection of user
Scanner get = new Scanner(System.in);


//display section.
System.out.println("Geometry Calculator");
System.out.println("Please select from the following menu:");
System.out.println("1. Calculate the Area of a Cirlce.");
System.out.println("2. Calculate the Area of a Rectangle.");
System.out.println("3. Calculate the Area of a Triangle.");
System.out.println("4. QUIT");
System.out.println("Please make a selection: ");
geoCalc = get.nextInt();
  

//having the user's option
switch (geoCalc)
{
case '1':
System.out.println("Please enter the circle's radius: ");
double r = get.nextDouble();

double areac = 3.14159 * r * r;

System.out.println("Area of Circle is : " + areac);
break;


case'2':
System.out.println("Please enter the length: ");
double l = get.nextDouble();
System.out.println("Please enter the width: ");
double w = get.nextDouble();
  
double arear = l * w;
  
System.out.println("Area of Rectangle is: " + arear);
break;
  
  
case '3':
System.out.println("Please enter the base: ");
double b = get.nextDouble();
System.out.println("Please enter height: ");
double h = get.nextDouble();
  
double areat = b * h * 0.5;
  
System.out.println("Area of Triangle is: ");
break;
  
  
case '4':
System.out.println("QUIT");
break;
  
}
  
  
}   
  
}

I tried running my code and I input 1 but it gives me back 1 and says built successful. Need help on what I'm doing wrong. Thanks!

Solutions

Expert Solution

/*
calculating area of a circle, calculating area of a rectangle, calculating area of a triangle, and quit.
*/


import java.util.Scanner;
public class GeoCalculator
{

    public static void main(String arg[])
    {

        char geoCalc; //number selection of user
        Scanner get = new Scanner(System.in);


//display section.
        System.out.println("Geometry Calculator");
        System.out.println("Please select from the following menu:");
        System.out.println("1. Calculate the Area of a Cirlce.");
        System.out.println("2. Calculate the Area of a Rectangle.");
        System.out.println("3. Calculate the Area of a Triangle.");
        System.out.println("4. QUIT");
        System.out.println("Please make a selection: ");
        geoCalc = get.next().charAt(0);


//having the user's option
        switch (geoCalc)
        {
            case '1':
                System.out.println("Please enter the circle's radius: ");
                double r = get.nextDouble();

                double areac = 3.14159 * r * r;

                System.out.println("Area of Circle is : " + areac);
                break;


            case'2':
                System.out.println("Please enter the length: ");
                double l = get.nextDouble();
                System.out.println("Please enter the width: ");
                double w = get.nextDouble();

                double arear = l * w;

                System.out.println("Area of Rectangle is: " + arear);
                break;


            case '3':
                System.out.println("Please enter the base: ");
                double b = get.nextDouble();
                System.out.println("Please enter height: ");
                double h = get.nextDouble();

                double areat = b * h * 0.5;

                System.out.println("Area of Triangle is: ");
                break;


            case '4':
                System.out.println("QUIT");
                break;

        }


    }

}


Related Solutions

Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The...
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The program to present the user with a menu where one of the shapes can be selected. Based on the selection made, the user enters the proper input, the program validates the input (i.e all entries must be greater than zero). Once the input is entered and validated, the intended area is calculated and the entered information along with the area are displayed. Area of...
Find the maximum area of a rectangle inscribed in a triangle of area A.(NOTE: the triangle...
Find the maximum area of a rectangle inscribed in a triangle of area A.(NOTE: the triangle need not necessarily be a right angled triangle).
/* Writing a program that displays the following: calculating area of a circle, calculating area of...
/* Writing a program that displays the following: calculating area of a circle, calculating area of a rectangle, calculating area of a triangle, and quit. */ import java.text.DecimalFormat; import java.util.Scanner; public class GeoCalculator {    public static void main(String arg[]) { char selection; Scanner get = new Scanner(System.in); //having user input DecimalFormat twoDigits = new DecimalFormat("0.00"); //formatting area to two decimal places //display choice of selection System.out.println("Geometry Calculator"); System.out.println("Please select from the following menu:"); System.out.println("1. Calculate the Area of a...
Determine the area of ​​the largest isosceles triangle that can be written into the unit circle....
Determine the area of ​​the largest isosceles triangle that can be written into the unit circle. It is advisable to let the corners in the triangle be given by (0.1), (x, y) and (−x, y), all on the unit circle, with x ≥ 0 but where we allow y to be negative.
(6) A diagonal of a rectangle in neutral geometry divides the rectangle into triangle I and...
(6) A diagonal of a rectangle in neutral geometry divides the rectangle into triangle I and triangle II. Can the angle-sum of triangle I be less than 180°? Why or why not?
JAVA program: Calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a...
JAVA program: Calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant data. HINT: use scanner object to take in length for square,...
Following the example of Circle class, design a class named Rectangle to represent a rectangle. The...
Following the example of Circle class, design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with specified width and height A method name getWidth() return the value of width A method named getHeight() returns value of...
Following the example of Circle class, design a class named Rectangle to represent a rectangle. The...
Following the example of Circle class, design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with specified width and height A method name getWidth() return the value of width A method named getHeight() returns value of...
Write a java program that contains 3 overloaded static methods for calculating area of a circle,...
Write a java program that contains 3 overloaded static methods for calculating area of a circle, area of a cylinder and volume of a cylinder. Also create an output method which uses JOptionPaneto display instance field(s) and the result of the computing. Then code a driver class which will run and test calling each of these overloaded methods with hard-coded data and display the data and the result of the calculation by calling output method. Thanks!!
The vertices of a triangle determine a circle, called the circumcircle of the triangle. Show that...
The vertices of a triangle determine a circle, called the circumcircle of the triangle. Show that if P is any point on the circumcircle of a triangle, and X, Y, and Z are the feet of the perpendiculars from P to the sides of the triangle, then X, Y and Z are collinear.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT