Java I CS 142 Week 02 Assignment.docx

advertisement
Java I CS 142 Week 02 Assignment
Your job will be to:
1. Create a GUI program that asks the user for two double numbers and a word (three JTextFields, one
for each, not JOptionPane step-by-step). You should also have a button “Compute”. The user will
enter a number in each of the two fields, a word in the third, and click on the “Computer” button.
Your program should then appropriate computation, and put the result in a fourth, non-editable
field for output.
2. You will use the word to determine what to do with the numbers.
3. If the word is “Add” or “aDD”, etc., add the numbers and display the sum (and the word “sum”).
4. Similarly for “Subtract” (Difference), “Multiply” (Product), and “Divide” (Quotient).
5. If the user types a word other than the above, either:
a. Interpret and do the right thing (like “Power”, “GCD”, “nPr”, “Moduluo”) if you are fishing
for extra credit. (the window should show me all possibilities, perhaps in a label.)
b. Display a sane message like “I don’t know how to “grep” two numbers”.
6. If the result of the calculation is negative, display a JOptionPane.ShowMessageDialog saying
“Negative result!)
Extra credit opportunities:
1. Go beyond the four basic arithmetic operations.
2. Use Try/Catch to handle parse failures.
3. Anything else you think is extra-credit-worthy.
Due 1 minute before noon on Thursday, January 24th.
Java I CS 142 Week 01 Assignment
p. 1 of 2
Download