Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: Based on Chapter 6, programming project 1 Hewlett-Packard has a tradition of creating stack-based calculators. Rather than using standard algebraic notation ( 1 +

Description:

Based on Chapter 6, programming project 1

Hewlett-Packard has a tradition of creating stack-based calculators. Rather than using standard algebraic notation ( 1 + 1 = ), the user would enter the values, then the operator. The calculator had an enter key to push each value onto a stack, then pop the stack when an operation key (e.g. + or -) was pressed.

Assignment:

Create aCalculatorclass that implements the providedStackCalculatorinterface

Constructor: + Calculator() Precondition:none Postcondition: a new calculator with an empty number stack

Methods: + public void enter(String entry) Precondition: entry is either a double value (operand) a recognized operator [ +, -, *, /] Postcondition: if the entry is a double, the value is pushed onto the calculators number stack. If an operator, the top two values are popped from the stack, the operation performed, and the result pushed onto the stack. Note: the second operand is popped first.

+ double peek() Precondition: number stack is not empty, otherwise throws EmptyStackException Looks at the number at the top of this stack without removing it from the stack. + double pop() Precondition: number stack is not empty, otherwise throws EmptyStackException Removes the number at the top of this stack and returns that value. + void clear() Removes all numbers from this stack. The stack will be empty after this call returns + boolean isEmpty Tests If the number stack of this calculator is empty + int size() Returns the number of values in this calculators number stack.

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

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions