Main Method: any suggestions?

Thread Solved

Join Date: Sep 2008
Posts: 91
Reputation: ezkonekgal is an unknown quantity at this point 
Solved Threads: 1
ezkonekgal ezkonekgal is offline Offline
Junior Poster in Training

Main Method: any suggestions?

 
0
  #1
Sep 21st, 2008
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.

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

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??
Last edited by cscgal; Sep 22nd, 2008 at 12:57 pm. Reason: Fixed code tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: Main Method: any suggestions?

 
0
  #2
Sep 21st, 2008
I would do something like this:

  1. if (!(option == JOptionPane.YES_OPTION))
  2. 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'.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 3
Reputation: fireheart1024 is an unknown quantity at this point 
Solved Threads: 2
fireheart1024 fireheart1024 is offline Offline
Newbie Poster

Re: Main Method: any suggestions?

 
0
  #3
Sep 21st, 2008
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 */
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC