Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Done in Java. Thanks. Specification: Taken from Project 7, Chapter 5, Page 178 * I have modified specification and requirements of this project * *

Done in Java. Thanks.

Specification:

Taken from Project 7, Chapter 5, Page 178

* I have modified specification and requirements of this project

*

* Ref: http://www.gigamonkeys.com/book/ (see chap. 10)

*

* In the language Lisp, each of the four basic arithmetic operators appears

* before an arbitrary number of operands, which are separated by spaces.

* The resulting expression is enclosed in parentheses. The operators behave

* as follows:

*

* (+ a b c ...) returns the sum of all the operands, and (+) returns 0.

*

* (- a b c ...) returns a - b - c - ..., and (- a) returns -a.

*

* (* a b c ...) returns the product of all the operands, and (*) returns 1.

*

* (/ a b c ...) returns a / b / c / ..., and (/ a) returns 1/a.

*

* Note: + * may have zero operand

* - / must have at least one operand

*

* You can form larger arithmetic expressions by combining these basic

* expressions using a fully parenthesized prefix notation.

* For example, the following is a valid Lisp expression:

*

* (+ (- 6) (* 2 3 4) (/ (+ 3) (* 1) (- 2 3 1)) (+))

*

* This expression is evaluated successively as follows:

*

* (+ (- 6) (* 2 3 4) (/ 3 1 -2) (+))

* (+ -6 24 -1.5 0.0)

* 16.5

*

* Requirements:

*

* - Design and implement an algorithm that uses Java API stacks to evaluate a

* Valid Lisp expression composed of the four basic operators and integer values.

* - Valid tokens in an expression are '(',')','+','-','*','/',and positive integers (>=0)

* - Display result as floting point number with at 2 decimal places

* - Negative number is not a valid "input" operand, e.g. (+ -2 3)

* However, you may create a negative number using parentheses, e.g. (+ (-2)3)

* - There may be any number of blank spaces, >= 0, in between tokens

* Thus, the following expressions are valid:

* (+ (-6)3)

* (/(+20 30))

*

* - Must use Java API Stack class in this project.

* Ref: http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html

* - Must throw LispExprEvaluatorException to indicate errors

* - Must not add new or modify existing data fields

* - Must implement these methods :

*

* public LispExprEvaluator()

* public LispExprEvaluator(String currentExpression)

* public void reset(String currentExpression)

* public double evaluate()

* private void evaluateCurrentOperation()

- You may add new private methods *

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions

Question

3. Choose an appropriate topic and develop it

Answered: 1 week ago

Question

LO1 Understand risk management and identify its components.

Answered: 1 week ago