General description for homework in this homework you need


Java - Calculator

General description for homework: In this homework, you need to modify the java source code file Calculator.java in chap 9, so that it takes the input parameter in a different way. For example, instead of taking one parameter "7 + 20" as the only argument, the modified version takes three parameters 7 + 20 as the argument list for the main method, and perform the same task of calculating the result for the expression. Here is the detail description for homework 9: No GUI is needed in this homework. No console input is needed, thus no need to import Scanner class. In the main method, then follow the STEPS below:

1. If the number of arguments supplied to the main method is not equal to 3, then output a line that says "Usage: java operand1 operator operand2" , and then quit the program. The program continues to the following steps if the argument number is 3.

2. If the second parameter is none of the following: + , -, x, / , %, then you need to output a line that says: "supported operators are +, -, x, / , and % " , and then quit the program. The symbol x above means multiplication. Attention: we CANNOT use symbol * as multiplication in our homework, and the reason is explained in the "Implementation requirement" below.

3. If the second parameter is any one of the following: + , -, x, / , %, then convert the first and the third parameter to int type, and then perform the required calculation. Save the calculated result to a local variable, and the result should be of int type.

4. Output to the console with the entire expression and calculated result , such as 7 + 20 = 27 Implementation requirement:

• In class java, you should have only one method: the main method. Do not put more classes or more methods in the homework, o/w, you are in the wrong track.

• User Calculator.java as a reference, and feel free to invoke APIs from String/StringBuilder.

• Notice that if the operator is / , and the result is int type, that means the division precision will not be kept. For example, 13 /3 will yield a result of 4.

• Notice that we use symbol x for multiplication operation, and this is different from textbook source code "Calculator.java" that uses symbol * for multiplication. We CANNOT use symbol * for multiplication in this homework, because symbol * has special meaning in command line, when symbol * itself is supplied as an individual String object in the command line.

• Symbol % means the remainder operator, and you can refer to textbook page 46 for explanation of remainder operator.

• Add suitable comments in the source code.

• Please read the above implementation details carefully BEFORE start coding.

• After finishing coding, you need to debug your program and test it multiple times with different input parameters provided for each test run.

• You can use command line to supply the arguments and test the program, or use Eclipse. Either way is fine.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: General description for homework in this homework you need
Reference No:- TGS02170795

Expected delivery within 24 Hours