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

[2579 byte] By [nickjavaa] at [2007-10-2 18:52:52]
# 1
you must equate your condition with OK_OPTION which is an int value which solves your problem. Hope this helps.Thanks,Ashok
Ashok_Telukuntlaa at 2007-7-13 20:15:36 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

right ok i have now changed my code, here is the updated code:

import javax.swing.JOptionPane;

class test

{

public static void main(String args[])

{

boolean outcome;

int x;

do

{

int newwall;

double[][] anArea = new double[3][];

anArea[0] = new double[6];

anArea[1] = new double[6];

anArea[2] = new double[6];

outcome = true;

while ((anArea[0][x] > 20000) | (anArea[0][x] <= 0))

{

anArea[0][x] = getX("Please enter the value for the height of the wall. The value must be between 0 and 20000.");

}

JOptionPane.showMessageDialog(null, "You inputted " + anArea[0][x]);

while ((anArea[1][x] > 20000) | (anArea[1][x]<= 0))

{

anArea[1][x] = getX("Please enter the value for the width of the wall. The value must be between 0 and 20000.");

}

JOptionPane.showMessageDialog(null, "You inputted " + anArea[1][x]);

anArea[2][x] = anArea[0][x] * anArea[1][x];

newwall = JOptionPane.showConfirmDialog(null, "Would you like to calculate the area for another wall?");

if (newwall == JOptionPane.YES_OPTION)

{

outcome = true;

}

else if (newwall == JOptionPane.NO_OPTION)

{

for(x = 0; x > anArea.length; x++);

{

JOptionPane.showMessageDialog(null, anArea[0][0] + " * " + anArea[1][0] + " = " + anArea[2][0]);

}

outcome = false;

}

else if (newwall == JOptionPane.CANCEL_OPTION)

{

JOptionPane.showMessageDialog(null,"You cancelled the operation");

outcome = false;

}

else

{

JOptionPane.showMessageDialog(null,"You cancelled the operation");

outcome = false;

}

}while(outcome == true);

}

public static double getX(String message)

{

double x = 0;

x = Double.parseDouble(JOptionPane.showInputDialog(null, message));

return x;

}

}

but im having trouble of thinking of a way of implenting a loop that increments by 1 each time. I want x to start at 0 and work up to 6 with increments of 1 each time yes is clicked. But how do you do that? i know its x ++ but where to put it?

nickjavaa at 2007-7-13 20:15:36 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
Line 21: You failed to initialize x
da_wannabesa at 2007-7-13 20:15:36 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4
The error is found here:while ((anArea[0][x] > 20000) | (anArea[0][x] <= 0))
da_wannabesa at 2007-7-13 20:15:36 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5

there is no problem with that line, that is fine because i want the users input to be more than and including 0 and less than 20000, im trying to get x to increment.

i know i have to give x a value, but where do i put it, and where do i put the increment.

Message was edited by:

nickjava

nickjavaa at 2007-7-13 20:15:36 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...