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:
while(true){
//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??

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)*/)
break;
}
//ur code after

/* may be this will work */

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.