Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 Stack valStk; // 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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

View writing as a strategic tool

Answered: 1 week ago

Question

what is a peer Group? Importance?

Answered: 1 week ago

Question

=+j Enabling a productive global workforce.

Answered: 1 week ago

Question

=+ Are you interested in creating or

Answered: 1 week ago

Question

=+working on a micro-multinational?

Answered: 1 week ago