Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Submitted by Soso on Thu, 11/25/2010 - 19:46
Write a program “simpleMath” that prompts the user to enter infix expressions. The expressions will be evaluated using an object of class “Evaluator”. Then, the result will be printed for the user. The program will continue until the user chooses to terminate by entering the word “END” as an expression.
\
\
Class “Evaluator” has the following members:
\
1. Data:
a. expressionQueue : a QUEUE that holds the infix expression operands and operations. For example, if the expression is: a + PI * ( b – area), the queue will contain:
b. operandsV: an unsorted LIST that contains objects of class “Operand”. This list is used to hold values for each operand in the expression. For example: for the example given in (a.), the list may contain:
a PI b area
12 3.14 2.3 2
c. Result: the result of the expression.
2. Methods:
a. Evaluator (): constructor.
b. Evaluate(String): receives the infix expression as a string and stores its result in the data member “Result”. This method must call all the three private methods.
c. getResult(): returns “Result” value.
d. stringToQueue(string): receives the infix expression string, from method “Evaluate”, and stores its operands and operations in “expressionQueue”. Assume that operands and operations are separated by one space and that operands names do not contain spaces.
e. setOperands(): prompt the user to enter a value for each operand in the queue, and fills “operandsV” list.
f. evaluateInfix(): evaluates the infix expression using “expressionQueue” and “operandsV” and stores the infix result in “Result
1 answer
Similar entries
- How to call store procedure(sequel server) in Java and how to retrieve data from result set
- Java Assertion, Java Assertion Classes
- Second Form of Assertion
- Java String Replace Example
- SCJP Exam Objectives, Java Developer SCJP Resources
- Java String Split Example
- Java ArrayList, Java ArrayList Tutorial
- Java byte variable assignment
- Java Class Example
- Java Vector, Java Vector Tutorial

Send us a snippet and we will gladly help you.