# [Solved] Problem with Area Calculator Code!

• August 24th, 2014, 03:35 AM
tazeunite00
[Solved] Problem with Area Calculator Code!
Hi there.

I am beginning to learn Java and have decided to create an area calculator. But I am having a big problem.
Code :

```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?

• August 24th, 2014, 03:43 AM
Re: Problem with Area Calculator Code!
Generally I would not advise using Boolean types as input variables.
the type that reads the exit command to a String perhaps? Then ensure the
text entered matches the command to exit the loop.

• August 24th, 2014, 03:50 AM
tazeunite00
Re: Problem with Area Calculator Code!
Hi.

Thanks for your help, will give it a try now!