Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do this using Netbeans and show your code. Thanks! Develop a class for calculating the value of a string that specifies symbols in reverse-Polish

Please do this using Netbeans and show your code. Thanks!

Develop a class for calculating the value of a string that specifies symbols in reverse-Polish notation (RPN). You can assume that the string is space-delimited; i.e., each of tokens in the string will be separated by spaces. Legal tokens include double literals and the symbols +, -, *, and /. For example, 23.3 5 16.2 + 8 * - would represent 23.3 - (5+16.2)*8. Your class will contain a method that accepts such a string as input and returns the double RPN value of the string. Your class does not have to have anything in main(); your testing will be done using JUnit.

Rather than developing your own stack to support the project, you should use the Stack class provided in java.util. Its specification, in part, is below: public class Stack < E> extends Vector { public Stack(); public Boolean empty(); public Object peek() throws EmptyStackException; // returns top without popping public Object pop() throws EmptyStackException; public Object push(Object item); }

Guidance: a. You will want to use java.util.Scanner to assist in parsing the input string. Use the stack to hold the double values; storing as Doubles would be best. b. Your RPN method must contain error-handling. For example, if a mathematical symbol suggests popping 2 numbers and the stack doesnt have 2, you should raise the InvalidRPNString exception (you will have to create this exception yourself). If the stack is not empty when the string is exhausted (after popping the last value), this is an error also. Anything in the string other than the 4 math symbols and valid double literals is an error. Divide by 0.0 is an error. c. Thorough testing using JUnit is required. Your JUnit class should run a series of tests to demonstrate proper operation of the code, including properly raising exceptions if the RPN string is not valid. Note: the only exception you should throw is InvalidRPNString; any other exception should be caught and re-thrown as this exception.

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

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago