QuestionQuestion

Use the STATE DESIGN PATTERN to implement a simple calculator. The calculator will accept only positive integer numbers and two types of operators, + and -. For example, an input could be 9 + 10 + 10 - 2
1) You should design the state machine first and then translate it into the state design pattern
2) Your calculator must compute correctly the expression
3) You must handle the cases where users type in invalid inputs (e.g. 10.3 or *)
Please submit your resulting code and a short Word document explaining the rationale behind your code.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

* Calculator class
*/
public class Calculator {

// State variable
private CalculatorState state;

// Constructor
public Calculator() {
    reset();
}

// Method to reset state machine
public void reset() {
    this.state = new AdditionState(0);
}

// Method to calculate input line
public int calculate(String line) throws NumberFormatException {
    for (char c: line.toCharArray...

By purchasing this solution you'll be able to access the following files:
Solution.PNG, Solution.docx, Solution.java, Solution1.java, Solution2.java and Solution3.java.

$60.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats