
write java program to offer a menu which contains 3 choices to make calculation on 3 shapes.use method for each calculation.

import java.util.Scanner;
public class CalculateAreaOfShapes{
public static void main(String []args){
int choice;
Scanner scanner=new Scanner(System.in);
System.out.println("1.For circle area.");
System.out.println("2.For square area ");
System.out.println("3.For Rectangle area");
System.out.println("Input your choice : ");
choice=scanner.nextInt();
switch(choice){
case 1: System.out.println("Input radius of circle : ");
float radius=scanner.nextFloat();
float pi=(float) 3.14;
float area=pi*radius*radius;
System.out.println("Area of circle = "+area);
break;
case 2:System.out.println("Input side of square : ");
float length=scanner.nextFloat();
area=length*length;
System.out.println("Area of your square = "+area);
break;
case 3:System.out.println("Input length of rectangle : ");
length =scanner.nextFloat();
System.out.println("Input width of rectangle : ");
float width=scanner.nextFloat();
area=length*width;
System.out.println("Area of rectangle = "+area);
break;
default: System.out.println("Your choice is not correct.");
}
}
}
Description :Here we are calculating area of 3 shapes according to user choice. If user input 1 then we calculate circle area as Formula
area of circle=3.14*radius*radius
If User's choice is 2 then your program give you output of square area. Formula of square-
area of Square=length*width; where length and width are same
If choice is 3 then it will generate area of rectangle.Formula is -
Area of rectangle = length*width .
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.