Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment4: Evaluate Arithmetic Expressions. Requirements: Implement a concrete ArrayStack class that extends the IStack interface as we discussed in the class (any other different Stack
Assignment4: Evaluate Arithmetic Expressions.
Requirements:
- 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).
- Write a test class called Evaluate and a method that evaluates an arithmatic expression, which is given by a string.
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 } }
public interface IStack {
abstract public int size();
//returns size of stack abstract public Object top();
//returns top of stack abstract public Object pop();
//removes top of stack and returns value abstract public void push(Object x) throws FullStackException;
//inserts data object to top of stack abstract public boolean isEmpty();
//returns true or false if stack is empty
}
- Your implementation is required to use the IStack interface we discussed in the class.
- 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. - 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 "/".
Grading Criteria:
- Please make sure your program compiles, otherwise your submission will not be graded and you will receive zero.
- Point deduction rule:
- Compile warning: 3 points each.
- Minor error: such as not meeting the assignment input/output requirement, 5 points each.
- Major error: examples include, infinite loop, runtime errors, any runtime exception, 15 points each.
- Any code not compliant to the assignment requirement (e.g., not using IStack interface or ever using generic programming) will not be graded and you will receve zero.
- 20 point penalty if your program works with division operator "/".
- (40%) Correct implementation of IStack.java, ArrayStack.java and StackFullException.java.
- (40%) Correct implementation of Evaluate class with the expression method that correctly evaluates the expression with +, - and * operators.
- (10%) The above expression method supports the parentheses ().
- (10%) Correct README file (with the required contents).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started