Evaluate Arithmetic Expressions Solution

$30.00

Category:

Description

Requirements:

  1. Implement a concrete ArrayStack class that extends the IStack interface as we discussed in the class (any other different Stack class implementation, even if it is implemented by yourself, will not receive any credit).
  2. Write a test class called Evaluate and a method that evaluates an arithmatic expression, which is given by a string.

“`java

import java.util.Scanner;

public class Evaluate {

public static void main(String[] args) {

// your implementation

// obtain user’s input from keyboard

// invoke method expression() to get the result and print it out

}

public static int expression(String str) {

// return the value

}

}

“`

  1. Your implementation is required to use the IStack interface we discussed in the class.
  2. provide a necessary test case to verify the result. For example,

`14-3*4+2*5-6*2 (should return 0) `

In another example,

`14-3*(4+2*(5-6))*2 (should return 2)  `

You may want to test all possible corner conditions to make sure your implement is inclusive.

  1. Your implementation only considers +, – and * operators, as well as the parentheses (), and does not need to consider other operators and brackets. In particular, your code should not work with division operator “/”.

error: Content is protected !!