Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

Students also viewed these Databases questions