| | |
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 |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card character class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting researchinmotion scanner se server service set sms software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows





