| | |
Main Method: any suggestions?
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 91
Reputation:
Solved Threads: 1
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.
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??
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)
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??
Last edited by cscgal; Sep 22nd, 2008 at 12:57 pm. Reason: Fixed code tags
•
•
Join Date: Mar 2004
Posts: 763
Reputation:
Solved Threads: 38
I would do something like this:
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'.
java Syntax (Toggle Plain Text)
if (!(option == JOptionPane.YES_OPTION)) stop = true;
![]() |
Similar Threads
- Troubles with printing triangles (Java)
- First time using JLabel and JTextArea. Please help!!! (Java)
- Average of prime number between 1 & 100 (C#)
- Identifier out of scope (C#)
- Homework HELP!!! (Java)
- Linked List Retrieve Method (C)
- Would someone be so kind as to view and verify... (Java)
- Recursion Program/Code I'm having issues with... (Java)
- Java Multidimensional Arrays (Java)
Other Threads in the Java Forum
- Previous Thread: NetBeans Menuitem click issue;)
- Next Thread: Stack
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character chat class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list loops mac map method methods mobile netbeans newbie notdisplaying number online printf problem program programming project properties qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor





