This was my second project as a beginner in Java programming. Please provide feedback/ tips on my program.
import java.util.Scanner;
public class Area {
public static void main(String[] args) {
Scanner Area = new Scanner (System.in);
double length, width,totalArea, height;
String shape, unit;
int loop = 0;
while (loop == 0){
System.out.println("Which shape do you want to find the area?");
shape = Area. next();
switch (shape) {
case "rectangle":
System.out.println("Please enter the leghth of the rectangle: ");
length = Area. nextDouble ();
System.out.println("Please enter the width of the rectangle: ");
width = Area. nextDouble();
System.out.println("What is the unit of the shape?");
unit = Area.next();
totalArea = length*width;
System.out.println(totalArea+unit);
break;
case "square" :
System.out.println("Please enter the leghth of the square: ");
length = Area. nextDouble ();
System.out.println("Please enter the width of the square: ");
width = Area. nextDouble();
System.out.println("What is the unit of the shape?");
unit = Area.next();
totalArea = length*width;
System.out.println(totalArea+unit);
break;
case "triangle" :
System.out.println("Please enter the base of the triangle: ");
length = Area. nextDouble ();
System.out.println("Please enter the height of the triangle: ");
width = Area. nextDouble();
System.out.println("What is the unit of the shape?");
unit = Area.next();
totalArea = ((length*width)/2);
System.out.println(totalArea+unit);
break;
case "parallelogram" :
System.out.println("Please enter the base of the parallelogram: ");
length = Area. nextDouble ();
System.out.println("Please enter the height of the parallelogram: ");
width = Area. nextDouble();
System.out.println("What is the unit of the shape?");
unit = Area.next();
totalArea = length*width;
System.out.println(totalArea+unit);
break;
case "circle" :
System.out.println("Please enter the radius of the circle: ");
length = Area. nextDouble();
System.out.println("What is the unit of the shape?");
unit = Area.next();
totalArea = 3.14*(Math.pow(length, 2));
System.out.println(totalArea+unit);
break;
case "rhombus" :
System.out.println("Please enter the first diagonal of the rhombus: ");
length = Area. nextDouble();
System.out.println("Please enter the second diagonal of the rhombus: ");
width = Area. nextDouble();
System.out.println("What is the unit of the shape?");
unit = Area.next();
totalArea = ((length*width)/2);
System.out.println(totalArea+unit);
break;
case "trapezoid" :
System.out.println("Please enter the first base of the trapezoid: ");
length = Area. nextDouble();
System.out.println("Please enter the second base of the trapezoid: ");
width = Area. nextDouble();
System.out.println("Please enter the height of the trapezoid: ");
height = Area.nextDouble();
System.out.println("What is the unit of the shape?");
unit = Area.next();
totalArea = (((length+width)*height)/2);
System.out.println(totalArea+unit);
break;
default:
System.out.println("The shape you entered is not recongnized");
}
}
}
}