In: Computer Science
/*
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!
/*
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;
}
}
}


