Hi there.
I am beginning to learn Java and have decided to create an area calculator. But I am having a big problem.
import java.util.Scanner; import static java.lang.System.out; import java.lang.Math; public class AreaCalculator { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String shape; double width, height, radius, base, area; boolean wantToExit = false, exit = false; out.println("Welcome to the Area Calculator!"); out.println("Please enter all data without a measurement!\n"); while(exit == false) { out.print("Please enter the shape: "); shape = keyboard.nextLine(); if(shape.equals("square") || shape.equals("rectangle")) { out.print("Please enter the width: "); width = keyboard.nextDouble(); out.print("Please enter the height: "); height = keyboard.nextDouble(); area = width * height; out.println("\nThe area is: " + area); } else if(shape.equals("triangle")) { out.print("Please enter the base size: "); base = keyboard.nextDouble(); out.print("Please enter the height: "); height = keyboard.nextDouble(); area = (base / 2) * height; out.println("\nThe area is: " + area); } else if(shape.equals("circle")) { out.print("Please enter the radius (half of diameter): "); radius = keyboard.nextDouble(); area = Math.PI * Math.sqrt(radius); out.println("\nThe area is: " + area); } else { out.println("Sorry, we do not currently support that shape!"); } out.print("Do you want to exit: (true/false) "); wantToExit = keyboard.nextBoolean(); if(wantToExit == true) { out.print("\nOkay, goodbye!"); exit = true; } else { exit = false; } } keyboard.close(); } }
When I run this and choose true to exit the loop. The message "Sorry, we do not currently support that shape!" appears.
Why is this and how can I fix this?
Regards, Bradley.