4 First Version
4 First Version
Start Assignment
Overview
Due Date is listed in the Assignment description here on Canvas and in your Canvas Calendar. (https://cascadia.instructure.com/calendar)
This assignment should be doable within the time-frame given. If you find yourself having difficulty, please seek out extra help from the
instructor.
For this assignment, you should start, finish, and do all the work on your own. If you have questions, please contact the instructor.
Purpose:
Review what you've learned so far, and demonstrate that you have the ability to independently apply what you've learned to solve a
programming challenge.
For this assignment you will be specifically be focusing on Chapters 14 (and earlier) in order to write a program that uses a Stack to create a
program that evaluates mathematical expressions written in Reverse Polish Notation (https://en.wikipedia.org/wiki/Reverse_Polish_notation)
(which is commonly abbreviated as RPN).
Background:
When we write out a mathematical expression we normally we write the operators between the operands, like so: " 3 + 4 ". We call this an
'infix' notation (my personal mnemonic is that the operators are in-between the numbers).
In Reverse Polish Notation (https://en.wikipedia.org/wiki/Reverse_Polish_notation) the operators follow the operands, like so: " 3 4 + ". We
call this a 'postfix' notation.
One of the nice features of postfix notation is that the order of operations is determined by the expression itself, unlike infix notation which
forces you to memorize PEMDAS, etc. This is accomplished by immediately applying any operators that we see, as we read the expression
from left to right.
So how do we keep track of what we should be applying the operators to? By pushing operands (numbers) onto a stack as we read from left
to right. That way, when we encounter an operator we can pop as many operands off the stack as we need, apply the operator to the
numbers, and then push the result back onto the stack.
Task:
This assignment will give you practice with the classes and interfaces that we've been examining in the Java Collections Framework,
specifically the Stack class.
You MUST build on the provided starter project (you will be penalized for starting a new Java file from scratch). You may find it useful to look
up 'labeled continue' statements before digging into the provided starter code.
The program has been started for you (so that you can focus more on the data structures and algorithms and less on the user interface code).
Your program needs to provide the RPN calculator functionality (as described in the 'Background' section) AND it needs to produce output that
is the same as what's listed in the 'Example Transcript' section, below.
Notice that the program can run in one of two modes: an 'explaining' mode where it shows the user exactly how it's evaluating the expression
at each step and a 'brief' mode where it just shows the end result (without showing any intermediate steps). Your program must be able to do
the same.
Note that there is now a video that walks you through the sample code, giving you a high level overview of what different parts of the
code are intended to do (https://cascadia.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=d2ecdce2-4ad2-493f-883d-adf00178657a) .
Example Transcript
User input is listed in large, bold underlined, highlighted text.
Note that the menu options for the main menu are case INsensitive. For example, you should be able to type in upper case A or lower case
1 2 +
y
y
1 2 +
n
y
1 2 3 + +
n
y
Now, any time that you want to test these inputs you can copy the entire file, run your program, and paste it into the program (using Control-V
or Command-V, or using VSCode's Edit -> Paste menu option)
IMPORTANT NOTE #2: Your instructor will test your program by pasting all the inputs listed below into your program. For full credit your
program must reproduce the following output exactly. (And in addition, your program must of course also work correctly with any other
expressions even if they're not listed in the example transcript)
RPN calculator
Supported operators: + - * /
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
RPN calculator
Supported operators: + - * /
RPN calculator
Supported operators: + - * /
RPN calculator
Supported operators: + - * /
RPN calculator
Supported operators: + - * /
RPN calculator
Supported operators: + - * /
RPN calculator
Supported operators: + - * /
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
Type your RPN expression in so that it can be evaluated: // There's like 7 spaces here - everything star
Would you like me to explain how to expression is evaluated? (y or Y for yes, anything else means no) n
ERROR! Ran out of operands (numbers)
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) y
RPN calculator
Supported operators: + - * /
Type your RPN expression in so that it can be evaluated: // There's like 7 spaces here - everything st
Would you like me to explain how to expression is evaluated? (y or Y for yes, anything else means no) y
We WILL explain the evaluation, step by step
ERROR! Ran out of operands (numbers)
Would you like to evaluate another expression? (y or Y for yes, anything else to exit) byebye
Thank you for using RPN Calculator!
Every file that you turn in should have a comment at the top of the file that contains the following:
Your name (first and last)
The name of this class (“BIT 143”)
The year and quarter
The assignment number, including the revision number, which starts at 0 (“A2.0”)
If you’re handing this in again for a regrade, make sure to increase the minor version number by one (from “A2.0”, to “A2.1").
That said, your instructor expects that you'll hand in the following files:
Grading Criteria:
Please examine the rubric that's attached to this assignment (it should be listed below)
A4_RPN_Reverse_Polish_Notation
This includes the use of good variable names, comments on each class and each method, 5 pts
using local variables when possible, correct use of generics and the other standard style
guidelines.
Total Points: 15