For today's lab test, you need to write a Java program Calculator.java, that takes as input a simple mathematical expression and evaluates the expression. A simple mathematical expression contains two operands that will be input individually. You need to implement the addition, subtraction and multiplication on integers in your program. Note that the user input is NOT case sensitive, which means "Add" or "ADD" are all valid input. In addition, you need to count the number of completed calculations performed, and output this when the user quits the program.
Example Output
Welcome to the Calculator program.
Please enter your name:
YiYi, please enter "Add" for addition, "Minus" for subtraction, "Multiply" for multiplication, or "Exit" to quit :
AddEnter the first number:
2Enter the second number:
22The value of 2 + 22 is:
24Yi, please enter "Add" for addition, "Minus" for subtraction, "Multiply" for multiplication, or "Exit" to quit :
multiplyEnter the first number:
3Enter the second number:
5The value of 3 * 5 is:
15Yi, please enter "Add" for addition, "Minus" for subtraction, "Multiply" for multiplication, or "Exit" to quit :
AdddError: Addd is an invalid input
Yi, please enter "Add" for addition, "Minus" for subtraction, "Multiply" for multiplication, or "Exit" to quit :
ExitYi completed 2 calculation.
Thank you for using the program. Goodbye.
File you must submit to xian@engr.sc.edu before the lab ends (29th, Sep. 4:00 pm):
Calculator.java
No late submission accepted!
Good luck!
No comments:
Post a Comment