943,671 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 956
  • Java RSS
Sep 21st, 2008
0

Main Method: any suggestions?

Expand Post »
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.

JAVA Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 9
Solved Threads: 1
Junior Poster
ezkonekgal is offline Offline
109 posts
since Sep 2008
Sep 21st, 2008
0

Re: Main Method: any suggestions?

I would do something like this:

java Syntax (Toggle Plain Text)
  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'.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Sep 21st, 2008
0

Re: Main Method: any suggestions?

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 */
Reputation Points: 10
Solved Threads: 2
Newbie Poster
fireheart1024 is offline Offline
3 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: NetBeans Menuitem click issue;)
Next Thread in Java Forum Timeline: Stack





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC