Tuesday, September 29, 2009

Lab Test 01

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:

Yi

Yi, please enter "Add" for addition, "Minus" for subtraction, "Multiply" for multiplication, or "Exit" to quit :

Add

Enter the first number:

2

Enter the second number:

22

The value of 2 + 22 is:

24

Yi, please enter "Add" for addition, "Minus" for subtraction, "Multiply" for multiplication, or "Exit" to quit :

multiply

Enter the first number:

3

Enter the second number:

5

The value of 3 * 5 is:

15

Yi, please enter "Add" for addition, "Minus" for subtraction, "Multiply" for multiplication, or "Exit" to quit :

Addd

Error: Addd is an invalid input

Yi, please enter "Add" for addition, "Minus" for subtraction, "Multiply" for multiplication, or "Exit" to quit :

Exit

Yi 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: