hello, it's me again.

As you have noticed, i am working on an assignment that my teacher gave me. It's 20% of my midterm exam. I posted the threads "Need urgent help! please", "I need help with my program", and the "Help with my main method."

I am having problems again with my main method.

public static void main(String args[]) {
		boolean stop = false;
		JOptionPane.showMessageDialog(null,  "Hello! I hope you have a wonderful time using the calculator.  = ]", "Welcome", JOptionPane.PLAIN_MESSAGE);	 
		JOptionPane.showMessageDialog(null,  "Note: \nEnter Infix expressions with spaces in between.", "Welcome", JOptionPane.PLAIN_MESSAGE);
		while (!stop){	
			String infix = JOptionPane.showInputDialog("Enter Mathematical expression here:");
			String output = "The expression in Postfix is: " +  convertToPostfix(infix);
			JOptionPane.showMessageDialog(null, output);
			String answer = "The answer to the equation:  " + evaluate(convertToPostfix(infix));
			JOptionPane.showMessageDialog(null, answer);
			int option = JOptionPane.showConfirmDialog(null,"Do you want evaluate an expression?", "Calculator", JOptionPane.YES_NO_OPTION);   
				if (option == 1){
					stop = true;
		}JOptionPane.showMessageDialog(null,  "Thank you for using the calculator.\n Have a nice day!\nGob Bless  = ]");

This is how it suppose to do:
//get input
//show postfix
//show answer
//asks the user to that if he wants to input again
if YES do the while loop again. if NO, exit while and ouput "thank you for using the calculator

but it seems that even if NO is your answer, it still asks an input.. what changes should i do??

9 Years
Discussion Span
Last Post by fireheart1024

I would do something like this:

if (!(option == JOptionPane.YES_OPTION))
    stop = true;

I have no idea what the values are for the constants, so always better to use the constant name rather than a value like '1'.


ur program is perfectly write but i don't know what's wrong with it.
Maybe try using this:-

while(true) {
//ur code.....
if(option==JOptionPane.NO_OPTION /*(or 1)*/)
//ur code after

/* may be this will work */

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.