Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: [Solved] Problem with Area Calculator Code!

1. ## [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.
```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)
{
shape = keyboard.nextLine();

if(shape.equals("square") || shape.equals("rectangle"))
{
width = keyboard.nextDouble();
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();
height = keyboard.nextDouble();

area = (base / 2) * height;
out.println("\nThe area is: " + area);
}
else if(shape.equals("circle"))
{

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?

2. ## 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.

3. ## The Following User Says Thank You to Ada Lovelace For This Useful Post:

GregBrannon (August 24th, 2014)

4. ## Re: Problem with Area Calculator Code!

Hi.

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