Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

1 Assignment Policies Collaboration Policy. The project is to be completed individually: each student must hand in the student's own answers. It is acceptable for

1 Assignment Policies Collaboration Policy. The project is to be completed individually: each student must hand in the student's own answers. It is acceptable for students to collaborate in understanding the material but not in solving the problems or programming. Use of the Internet is allowed, but that should not include searching for existing solutions. Under absolutely no circumstances code can be exchanged among students. The code presented in the book and in class can be used. 2 Assignment You have to implement a calculator that would pars evaluate an arbitrary expression that may 1) Rational numbers (e.g., 4.5669 or -3.5); 2) Parentheses '(' and ')'; 3) Operators "+", "-", "*", "/", and "^". The latter operator is that of exponentiation, which, has the highest precedence. Your code must handle rational exponentsincluding the negative ones.

2 Your program must 1 use a recursive-descent technique, as explained in class, based on the following grammar for expressions, as discussed in class: '+' '-' '*' '/' '('')' '.' ' 0', '1', '2' ... '9' Your program must correctly handle all error conditions (it must never crash!). You may use all Java mathematical libraries available to you.2 3 Additional features If your program is ready before the deadline, you can get extra 15 points by allowing your expressions to contain identifiers. In other words, your program should recognize an assignment: '=' and process it by printing the value of the identifier. For example, you could write x = 20, which will result in your program displaying 20. Once an identifier has been assigned a value, it can be used in subsequent expressions (e.g., x+3). A subsequent assignment can change the value of the identifier. You should store all identifiers in a hash table. An identifier can be created or modified only via the assignment. If a non-existing identifier is referenced, your program must return an error. 1 If the code does not implement this technique (for example, if it uses the direct stack operations as shown in the textbook), the grade for this assignment will be 0. 2 For instance to implement rational exponentiation ab = eb ln a you may use the Java Math methods for finding natural logarithms and exponentiation..

3 Extra points for this feature will be given only if the rest of the program is working. 4 Submission instructions Submit a single file named Expression.zip through Canvas that includes Calculator.java and CalculatorTest.java with your test cases.. Make sure that you test your code well! Up to 20 points will be deducted for each of the following problems: 1) An ill-formed expression is not detected or a wrong error message is given; 2) The calculation result is wrong. The code must be well-commented. The code that does not compile or crashes will be found unacceptable.

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

Quantitative Analysis For Management

Authors: Barry Render, Ralph M. Stair, Michael E. Hanna

11th Edition

9780132997621, 132149117, 132997622, 978-0132149112

More Books

Students explore these related Programming questions