Question
Regardless of what is stated in the details of this excercise. I only need help on the first part of this assignment. I'm breaking it
Regardless of what is stated in the details of this excercise. I only need help on the first part of this assignment. I'm breaking it down so that it has one question per post. What code do I need to enter in between the bolded area in order to complete the method? Please HELP!
Create and use a stack ADT (Abstract Data Type) to be used with a simple calculator.
The calculator should be capable of evaluating the following simple expression:
2.3 * 1.2 + 14.0
The operators for the simple calculator are as followed:
Addition +
Subtraction -
Multiplication *
Division /
This excercise provides one class: Calculator. The Calculator class is in incomplete format. You must fill in the details to make the class complete.
For the Calculator class, you will need to complete:
doOp()
repeatOps()
evalExp()
Only the bodies of these 3 methods need to be completed. You do not need any additional code to make them work.
This is what I have so far & everything needs to be done in Java...
public class Calculator {
private StackvalStk; // the operand stack private Stack opStk; // the operator stack private int prec[] = new int[128]; // used for comparing precedent of operators // Constructor public Calculator() { valStk = new Stack (10); opStk = new Stack (10); prec['$'] = 0; // Used to signal end of input condition prec['+'] = 1; // + and - have lower precedence than * and / prec['-'] = 1; prec['*'] = 2; prec['/'] = 2; } /** * Take two operands from the valStack along with an operator from opStack and perform the * operation, pushing the result back on the valstack. * * @param obj * the object to be pushed */ void doOp() { // Begin: Insert your code here to complete the method // End: Of your code }
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