The calculator works as follows: if number, push to a stack if operator, pop two numbers, operate on them, and push the result if I hit an operator and there are not two numbers on the stack, it's a bad expression if I get to the end of the expression and there is not exactly one number on the stack, it's a bad expression. YOUR IMPLEMENTATION, 30 points: 10 - the input to output happening without a crash 10 for implementing LinkedListBasedStack 10 for implementing ArrayList YOUR CALCULATOR ONLY NEEDS TO WORK FOR +, -, and * YOUR CALCULATOR ONLY NEEDS TO WORK ON INTEGERS.    RPNStringTokenizer.java package template; import java.util.ArrayList; public interface RPNStringTokenizer { public static ArrayList tokenize (String expression) { // take a string. If it is valid RPN stuff - integers or operators // - then put them in a list for processing. // anything bad (not int or one of the operators we like) and return a null.   // YOU WRITE THIS! return null; } }  RPNTester.java package template; import java.util.ArrayList; public class RPNTester { public static void main(String[] args) { // don't change this method! YourRPNCalculator calc = new YourRPNCalculator(new YourArrayListStack()); System.out.println("Testing ArrayList version"); testRPNCalculator(calc);   calc = new YourRPNCalculator(new YourLinkedListStack()); System.out.println("Testing LinkedList version"); testRPNCalculator(calc); }   private static void testRPNCalculator(SimpleRPNCalculator calc) { ArrayList testExpressions = new ArrayList<>(); testExpressions.add("1 1 +"); // 2 testExpressions.add("1 3 -"); // 2 testExpressions.add("1 1 + 2 *"); // 4 testExpressions.add("1 1 2 + *"); // 3 testExpressions.add("1 1 + 2 2 * -"); // 2 testExpressions.add("11 bv +"); // bad token testExpressions.add("2 3 + -"); // underflow on an operator testExpressions.add("2 3 + 4 5 -"); // leftover tokens // YOU SHOULD ADD MORE TEST CASES!   for (String s : testExpressions) { System.out.println(calc.calculate(s)); } } } SimpleRPNCalculator.java package template;   public interface SimpleRPNCalculator { public String calculate(String inputString);   /* * RPN (Reverse Polish Notation) is a postfix method of expression mathematical functions. * It is traditionally used to eliminate the necessity of parenthesis by removing the * order of operations and acting on operators as they occur. * * Very simply, INFIX notation "1 + 1" is represented in POSTFIX notation as "1 1 +" * Longer expressions may change radically. "1 + 2 * 3" assumes an order of operations, * while in POSTFIX, "2 3 * 1 +" or "1 2 3 * +" * * The calculator works as follows: * if number, push to a stack * if operator, pop two numbers, operate on them, and push the result * if I hit an operator and there are not two numbers on the stack, it's a bad expression * if I get to the end of the expression and there is not exactly one number on the stack, * it's a bad expression. * * FOR YOUR IMPLEMENTATION, 30 points: * 10 for making something that looks like it works - the input to output happening without a crash * 10 for implementing LinkedListBasedStack * 10 for implementing ArrayList * * YOUR CALCULATOR ONLY NEEDS TO WORK FOR +, -, and * * YOUR CALCULATOR ONLY NEEDS TO WORK ON INTEGERS. * * 5 bonus points for working on Doubles (this is a gimme) * 5 bonus points for implementing division / (this is deceptively hard, DO THIS LAST!) * * */ } YourArrayListStack.java package template; import java.util.ArrayList; public class YourArrayListStack implements YourStack { // YOU MUST USE THIS IMPLEMENTATION - just code the methods ArrayList theStack = new ArrayList<>();   @Override public void push(Integer i) {   }   @Override public Integer pop() { return null; }   @Override public Integer size() { return null; } } YourLinkedListStack.java package template;   public class YourLinkedListStack implements YourStack { // YOU MUST USE THIS IMPLEMENTATION - just code the methods private YourStackNode head = null; private Integer size = 0;   @Override public void push(Integer i) {   }   @Override public Integer pop() { return null; }   @Override public Integer size() { return null; } } YourRPNCalculator.java package template;   import java.util.ArrayList;   public class YourRPNCalculator implements SimpleRPNCalculator { // don't change these... YourStack theStack = null;   public YourRPNCalculator(YourStack stack) { theStack = stack; } @Override public String calculate(String inputString) { // this is probably helpful, but you can remove... ArrayList tokens = RPNStringTokenizer.tokenize(inputString); // here's the calculator logic! return null; } } YourStack.java package template; public interface YourStack { public void push (Integer i); public Integer pop(); public Integer size(); }   YourStackNode.java package template;   public class YourStackNode { // DO NOT CHANGE THIS! private Integer item; private YourStackNode next;   public Integer getItem() { return item; }   public YourStackNode getNext() { return next; }   public void setItem (Integer i) { item = i; } public void setNext (YourStackNode node) { next = node; } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
The calculator works as follows: if number, push to a stack if operator, pop two numbers, operate on them, and push the result if I hit an operator and there are not two numbers on the stack, it's a bad expression if I get to the end of the expression and there is not exactly one number on the stack, it's a bad expression. YOUR IMPLEMENTATION, 30 points: 10 - the input to output happening without a crash 10 for implementing LinkedListBasedStack 10 for implementing ArrayList YOUR CALCULATOR ONLY NEEDS TO WORK FOR +, -, and * YOUR CALCULATOR ONLY NEEDS TO WORK ON INTEGERS. 
 
RPNStringTokenizer.java

package template;

import java.util.ArrayList;

public interface RPNStringTokenizer {

public static ArrayList<String> tokenize (String expression) {

// take a string. If it is valid RPN stuff - integers or operators

// - then put them in a list for processing.

// anything bad (not int or one of the operators we like) and return a null.

 

// YOU WRITE THIS!

return null;

}

RPNTester.java

package template;

import java.util.ArrayList;

public class RPNTester {

public static void main(String[] args) {

// don't change this method!

YourRPNCalculator calc = new YourRPNCalculator(new YourArrayListStack());

System.out.println("Testing ArrayList version");

testRPNCalculator(calc);

 

calc = new YourRPNCalculator(new YourLinkedListStack());

System.out.println("Testing LinkedList version");

testRPNCalculator(calc);

}

 

private static void testRPNCalculator(SimpleRPNCalculator calc) {

ArrayList<String> testExpressions = new ArrayList<>();

testExpressions.add("1 1 +"); // 2

testExpressions.add("1 3 -"); // 2

testExpressions.add("1 1 + 2 *"); // 4

testExpressions.add("1 1 2 + *"); // 3

testExpressions.add("1 1 + 2 2 * -"); // 2

testExpressions.add("11 bv +"); // bad token

testExpressions.add("2 3 + -"); // underflow on an operator

testExpressions.add("2 3 + 4 5 -"); // leftover tokens

// YOU SHOULD ADD MORE TEST CASES!

 

for (String s : testExpressions) {

System.out.println(calc.calculate(s));

}

}

}

SimpleRPNCalculator.java

package template;

 

public interface SimpleRPNCalculator {

public String calculate(String inputString);

 

/*

* RPN (Reverse Polish Notation) is a postfix method of expression mathematical functions.

* It is traditionally used to eliminate the necessity of parenthesis by removing the

* order of operations and acting on operators as they occur.

*

* Very simply, INFIX notation "1 + 1" is represented in POSTFIX notation as "1 1 +"

* Longer expressions may change radically. "1 + 2 * 3" assumes an order of operations,

* while in POSTFIX, "2 3 * 1 +" or "1 2 3 * +"

*

* The calculator works as follows:

* if number, push to a stack

* if operator, pop two numbers, operate on them, and push the result

* if I hit an operator and there are not two numbers on the stack, it's a bad expression

* if I get to the end of the expression and there is not exactly one number on the stack,

* it's a bad expression.

*

* FOR YOUR IMPLEMENTATION, 30 points:

* 10 for making something that looks like it works - the input to output happening without a crash

* 10 for implementing LinkedListBasedStack

* 10 for implementing ArrayList

*

* YOUR CALCULATOR ONLY NEEDS TO WORK FOR +, -, and *

* YOUR CALCULATOR ONLY NEEDS TO WORK ON INTEGERS.

*

* 5 bonus points for working on Doubles (this is a gimme)

* 5 bonus points for implementing division / (this is deceptively hard, DO THIS LAST!)

*

*

*/

}

YourArrayListStack.java

package template;

import java.util.ArrayList;

public class YourArrayListStack implements YourStack {

// YOU MUST USE THIS IMPLEMENTATION - just code the methods

ArrayList<Integer> theStack = new ArrayList<>();

 

@Override

public void push(Integer i) {

 

}

 

@Override

public Integer pop() {

return null;

}

 

@Override

public Integer size() {

return null;

}

}

YourLinkedListStack.java

package template;

 

public class YourLinkedListStack implements YourStack {

// YOU MUST USE THIS IMPLEMENTATION - just code the methods

private YourStackNode head = null;

private Integer size = 0;

 

@Override

public void push(Integer i) {

 

}

 

@Override

public Integer pop() {

return null;

}

 

@Override

public Integer size() {

return null;

}

}

YourRPNCalculator.java

package template;

 

import java.util.ArrayList;

 

public class YourRPNCalculator implements SimpleRPNCalculator {

// don't change these...

YourStack theStack = null;

 

public YourRPNCalculator(YourStack stack) {

theStack = stack;

}

@Override

public String calculate(String inputString) {

// this is probably helpful, but you can remove...

ArrayList<String> tokens = RPNStringTokenizer.tokenize(inputString);

// here's the calculator logic!

return null;

}

}

YourStack.java

package template;

public interface YourStack {

public void push (Integer i);

public Integer pop();

public Integer size();

}

 

YourStackNode.java

package template;

 

public class YourStackNode {

// DO NOT CHANGE THIS!

private Integer item;

private YourStackNode next;

 

public Integer getItem() {

return item;

}

 

public YourStackNode getNext() {

return next;

}

 

public void setItem (Integer i) {

item = i;

}

public void setNext (YourStackNode node) {

next = node;

}

}

Expert Solution
Step 1

We have to write the code of given data we have to complete the given code by using the given data. We will write two classes implementing the YourStack interface using an ArrayList and a linked list. we have to create YourArrayListStack, YourLinkedListStack and RPNStringTokenizer.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY