## Sunday, October 8, 2017

### .charAt(0)

Challenge:  Write a program that presents the user a menu of four choices, “Circle”, “Square”, “Rectangle”, and “Exit” to calculate the area of one of these geometric objects. Once a choice is made, the program would ask the user for the data required to do the calculation. For example, if the user input were “Circle”, the program would prompt the user to enter the value of the radius of the circle.

import java.util.Scanner;

public class lab5_3
{
public static void main(String []args)
{

Scanner in=new Scanner(System.in);
System.out.println("1. Circle");
System.out.println("2. Square");
System.out.println("3. Rectangle");
System.out.println("4. Exit");

int choice=in.nextInt();

if (choice==1)
{
System.out.println("Enter the radius of the circle");

double r =in.nextDouble();
double circleArea=Math.PI *  Math.pow(r, 2);

System.out.printf("The area of the circle is: %.2f", circleArea);
System.out.println();
}

else if(choice==2)
{
System.out.println("Enter one dimension of the square");
double sideSquare = in.nextDouble();
double squareArea = Math.pow(sideSquare,2);
System.out.printf("The area of the square is: %.2f", squareArea);
System.out.println();
}

else if(choice==3)
{
System.out.println("Enter the length and width of your rectangle: ");
double width = in.nextDouble();
double length = in.nextDouble();
double rectangleArea = width*length;
System.out.printf("The area of the rectangle is: %.2f", rectangleArea);
System.out.println();

else if(choice==4)
{
System.out.println("Have a good one!");

else
{
System.out.println("Input Error!");
}
}

}