Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming: Create a function to evaluate infix double expressions. Your function should accept a string containing a valid infix expression of constant doubles, and

Java Programming: Create a function to evaluate infix double expressions. Your function should accept a string containing a valid infix expression of constant doubles, and return a double representing the value of the expression. If you call your function with the string "10.0 + 3 * 45.0" it should return the value 145.0. If you call it with the string "(10.0 + 3) * 45.0" it should return 585.0 1) Figure out how to parse the string into a series of tokens -- operands, operators, and parentheses. For the second example, you would probably want to turn the input string into an array of strings '(' '10.0' '+' '3' ') '*' '45.0', then use this array to drive the conversion to a value. You might find it helpful to look at java's StringTokenizer class. You will want to use the version of the appropriate function which takes a string, a list of terminators, and a boolean. 2) Once you have that working, then you will want to implement the "shunting yard algorithm" to convert your array of tokens into a value. This algorithm is described here: https://en.wikipedia.org/wiki/Shunting-yard_algorithm

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions