Contact us - +12567847275

double operandTwo

Assignment 3 – Infix Evaluator The purpose of this assignment is to implement the Stack ADT using an array and then to use it in an algorithm to evaluate an infix mathematical expression. This assignment draws from the material covered

Assignment03.java A complete Java program used to test your code. Your assignment is to write a class called ArrayStack that implements the Stackinterface Java interface using Array-based data. You will also complete the InfixEvaluator class by writing code for the unfinished evaluate method,
Assignment03.java file. 2 Specification Your implementation should meet the following specifications: 1. Your Stack implementation class should be named “ArrayStack”. 2. ArrayStack should implement all methods as described in the Stackinterface Java interface provided. The documentation comments constitute the specification for the ArrayStack class. 3. The Stack implementation should use a generic standard Java array (not an ArrayList or any other class) to hold the data for the Stack. 4. The Stack implementation should utilize security measures including: a. Maximum Capacity checks b. Array integrity checks 5. The Stack implementation must resize the standard Java array so that the capacity of the Stack can grow as new items are added.

package assignment;

/**
* CPS231 – Fall 2021
* Assignment 3 – Infix Evaluator using the Stack ADT
*
* February 6, 2021
*
* @author Adam Divelbiss
*
*/
public class Assignment03 {

public static void main(String[] args) {
// Evaluate the following expressions
// a=2,b=3,c=4,d=5,e=6
InfixEvaluator infixEvaluator = new InfixEvaluator();
infixEvaluator.setValue(‘a’, 2);
infixEvaluator.setValue(‘b’, 4);
infixEvaluator.setValue(‘c’, 3);
infixEvaluator.setValue(‘d’, 5);
System.out.println(“Testing infix expressions with:”);
System.out.println(” a = ” + infixEvaluator.valueOf(‘a’));
System.out.println(” b = ” + infixEvaluator.valueOf(‘b’));
System.out.println(” c = ” + infixEvaluator.valueOf(‘c’));
System.out.println(” d = ” + infixEvaluator.valueOf(‘d’));
System.out.println(“”);

testInfix(infixEvaluator, “a+b”, 6.0);
testInfix(infixEvaluator, “(a + b) * c”, 18.0);
testInfix(infixEvaluator, “a * b / (c – d)”, -4.0);
testInfix(infixEvaluator, “a / b + (c – d)”, -1.5);
testInfix(infixEvaluator, “a / b + c – d”, -1.5);
testInfix(infixEvaluator, “a^b^c”, 1.8446744073709552E19);
testInfix(infixEvaluator, “(a^b)^c”, 4096.0);
testInfix(infixEvaluator, “a*(b/c+d)”, 12.666666666666666);
testInfix(infixEvaluator, “e * (a – c) / (b – c)”, 0.0);
testInfix(infixEvaluator, “(b – c) * (a – c) / (b – c)”, -1.0);
System.out.println(“Done.”);

}
public static void testInfix(InfixEvaluator evaluator, String infixExpression, double expected)
{
final double TOLERANCE = 1.0e-9;
double result = evaluator.evaluate(infixExpression);
System.out.println(“Infix: “” + infixExpression + “”””””);
System.out.println(“”Result: “” + result);
if (Math.abs(result – expected) < TOLERANCE) {
System.out.println(“”TEST: OK””);
} else {
System.out.println(“”TEST: ERROR””);
}
System.out.println();
} // end testInfix

}

package assignment;

/**
* CPS231 – Fall 2021
* Assignment 03 – A class to evaluate infix expressions.
*
* @author adamdivelbiss
*
*/
public class InfixEvaluator {
/**
* private helper method to return the precedence value for a particular operator.
* @param operator
* @return
*/
private static int precedence(char operator) {
int result = -1;
switch (operator) {
case ‘(‘: case ‘)’: result = 0; break;
case ‘+’: case ‘-‘: result = 1; break;
case ‘*’: case ‘/’: result = 2; break;
case ‘^’: result = 3; break;
}
return result;
}
/**
* private helper method to compute the value of a basic infix operation
* @param operandOne
* @param operandTwo
* @param operator
* @return
*/
private static double compute(double operandOne

Solution:

15% off for this assignment.

Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!

Why US?

100% Confidentiality

Information about customers is confidential and never disclosed to third parties.

Timely Delivery

No missed deadlines – 97% of assignments are completed in time.

Original Writing

We complete all papers from scratch. You can get a plagiarism report.

Money Back

If you are convinced that our writer has not followed your requirements, feel free to ask for a refund.