java problem
ok i am trying to create a program which will calculate the area of a wall, and then using JOptionPane, ask the user if they want to work out the area of another wall. But once they say they do not want to create another calculation, it will display all areas in a message dialog.
Here is the code i got so far:
import javax.swing.JOptionPane;
class test
{
public static void main(String args[])
{
do
{
double height;
double width;
height = getX("Please enter the value for the height of the wall");
while ((height > 20000) | (height<= 0))
{
height = getX("Please enter the value for the height of the wall. The value must be between 0 and 20000.");
}
JOptionPane.showMessageDialog(null, "You inputted " + height);
width = getX("Please enter the value for the width of the wall");
while ((width > 20000) | (width<= 0))
{
width = getX("Please enter the value for the width of the wall. The value must be between 0 and 20000.");
}
JOptionPane.showMessageDialog(null, "You inputted " + width);
String menuOptions[] = {"Yes","No","Cancel"};
int result;
result = JOptionPane.showOptionDialog(null, "Continue Operation?", "Would you like to calculate the area for another wall?", 0,JOptionPane.QUESTION_MESSAGE, null, menuOptions, menuOptions[0]);
if (result == 0)
{
double y, x;
double[][] anArea = new double[2][];
anArea[0] = new double[6];
anArea[1] = new double[6];
for(x = 0; x < 6; x++)
{
anArea[0][x] = height;
anArea[1][x] = width;
}
}
}while(result == 0);
else if (result == 1)
{
double area;
for(x = 0; x < 6; x++);
{
area = anArea[0][x] * anArea[1][x];
JOptionPane.showMessageDialog(null, anArea[0][x] + " * " + anArea[1][x] + " = " + area);
}
}
else if (result == 2)
{
JOptionPane.showMessageDialog(null,"You cancelled the operation");
}
else
{
JOptionPane.showMessageDialog(null,"You cancelled the operation");
}
}
public static double getX(String message)
{
double x = 0;
x = Double.parseDouble(JOptionPane.showInputDialog(null, message));
return x;
}
}
i cant figure out how to make the program keep running until 'no' is selected.
And also i think something is wrong with the array
Any help?
Message was edited by: nickjava
nickjava

