$30
You will write a Java program to evaluate arithmetic expressions using four lines of input which you will get from the user. One example input and output is provided below. Please read the assignment description completely before beginning to write any code.
Example Input-1:
int x=3;
int y = 5 ; double z = 6 ;
(2+ 3*5 / 2 *x+ y* (126 +z*2));
Example Output-1:
713.0
Please make sure you follow these rules in your implementation:
1. Your program should have at least two static methods in addition to your main method. Try
to write your program as modular as possible (without overusing methods).
2. You are not allowed to use String methods other than:
• replace
• substring
• length
• contains
• indexOf
• lastIndexOf
• equals
• charAt
You can obviously use the + operator for string concatenation.
3. You are not allowed to use any other class then String, Integer, Double, and Scanner. Note that this does not mean that you cannot use datatypes like int, double, boolean etc. You can use the datatypes you have learned in class.
4. You can and should make use of all the subjects you have learned in class such as while loops, conditional statements, booleans, etc.
5. You can use methods from the Integer and Double classes. For example:
• Double.parseDouble(String arg0)
• Double.toString(double d)
• Integer.parseInt(String arg0)
• Integer.toString(int i)
Implementation Details:
• “input which you will get from the user” means you need to use Scanner.
• The first three lines are going to be your variables. You will use their types and values as given in the input. Note that z in the Example Input-1 is a double, so its value is 6.0.
• The fourth line will be the expression you are expected to evaluate and return the result of. Given expression can contain integers and/or doubles.
• Variable types in the input can change, but their types will be only int or double.
• Assume no erroneous input will be given.
• A few things to note on the input:
1. All the input lines end with a semicolon.
2. There can be any number of empty spaces anywhere after the variable type is given, up until the semicolon for the first three lines of input. (There are no empty spaces before the type keyword and there are no empty spaces after the semicolon.)
3. There can be any number of empty spaces anywhere up until the semicolon for the fourth line of the input. (There are no empty spaces after the semicolon.)
You should format the inputs and the expression so that you can operate on them easier.
• The order of precedence for the operations are parentheses first, then multiplication-division and then addition-subtraction. There won’t be any other operations.
• For operations with the same precedence, the order of operations is from left to right.
• Parentheses can be nested and will require special effort to handle.
Think carefully on how to write your code such that it can solve for inputs with nested parentheses.
• Operations performed need to consider the data types involved, for example, if you are doing integer division like 7/2, the answer should be 3; but if it is 7.0/2 the answer should be 3.5. This will also affect your result. If your answer is 65.0 (a double) but it was supposed to be 65 (an integer) this is a mistake.
• Assume that the operations will never cause an overflow/underflow situation, and no operation will result in a negative number.