Question: Write a java program with methods evalMD(String E) and evalE(String E) that recursively evaluates arithmetic expressions with +, -, *, / operators and positive integer

Write a java program with methods evalMD(String E) and evalE(String E) that recursively evaluates arithmetic expressions with +, -, *, / operators and positive integer operands. Both methods should return an int to the caller. Recursion should be used in both methods.

Test your program with:

12*4 = 48

12/4 = 3

12+4 = 16

12-4 = 8

12+4*2 = 20

12+4/2 = 14

12*4+2 = 50

12/4+2 = 5

And then try other longer valid expressions consisting of all +, -, *, / operators and positive integer operands.

Your main method in this program should demonstrate the use of your methods by allowing the user to enter an arithmetic expression as a string and receive output of the answer.

Quick starter code to get you started:

import java.util.Scanner; public class JJL4 { /*Method for the implementation of the multiplication(*) and division(/) operands that function in an arithmatic expression.*/ public static void evalMD(String s) { } /*Method for the implementation of the addition(*) and subtraction(/) operands that function in an arithmatic expression.*/ public static void evalE(String s) { } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = ""; System.out.println("Enter a positive arithmatic expression: "); s = in.nextLine(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!