How to get my second switch operations to work. import java.util.Stack; import java.util.Scanner; public class PostfixEvaluator {       private final static char ADD = '+'; private final static char SUBTRACT = '-'; private final static char MULTIPLY = '*'; private final static char DIVIDE = '/'; private final static char MODULUS = '%'; private final static char NEGATIVE = 'm'; private final static char EXCHANGE = 'r'; private final static char DUPLICATE = 'd'; private final static char PRINT = 'p'; private final static char PRINT_AND_REMOVE = 'n'; private final static char PRINT_ALL = 'f'; private final static char CLEARall = 'c'; private final static char QUIT = 'q'; private final static char HElP = '?';       private Stack stack;    public PostfixEvaluator() { stack = new Stack(); } public int evaluate(String expr) { int op1, op2, result = 0; String token; Scanner parser = new Scanner(expr); while (parser.hasNext()) { token = parser.next(); if (isOperator(token)) { op2 = (stack.pop()).intValue(); op1 = (stack.pop()).intValue(); result = evaluateSingleOperator(token.charAt(0), op1, op2); stack.push(new Integer(result)); } if (isCommand(token)); evaluateother(token.charAt(0), op1, op2);       } else stack.push(new Integer(Integer.parseInt(token))); } return result; } /////////////////////////////////////////////////////////////////////////////////// private boolean isOperator(String token) {        return (token.equals("+") || token.equals("-") ||token.equals("*") ||                token.equals("/") || token.equals("%") || token.equals("m")); }    private boolean isCommand(String token) {        return (token.equals("r") || token.equals("d") || token.equals("p") ||                token.equals("n") || token.equals("f") || token.equals("c") ||                token.equals("q") || token.equals("?")); } /////////////////////////////////////////////////////////////////////////////////// private int evaluateSingleOperator(char operation, int op1, int op2) { int result = 0;    switch (operation) { case ADD: // this is + result = op1 + op2; break; case SUBTRACT: // this is - result = op1 - op2; break; case MULTIPLY: // this is * result = op1 * op2; break; case DIVIDE: // this is / result = op1 / op2; break; case MODULUS: // this is %    result = op1 % op2;    break; case NEGATIVE: // this is m    int result = op1 * -op2;    break; } return result; }    private void evaluateOtherOperator(char commmand, int op1, int op2) {    int reslut = 0;       switch (operation) // This is second switch (operation)    {    case EXCHANGE: // this is r        result =        break    case DUPLICATE: // this is d        result        break    case PRINT: // this is p        result        break    case PRINT_AND_REMOVE: // this is n               break    case PRINT_ALL: // this is f        System.out.println(stack)        break    case CLEARall: // this is c        stack.clear();        break    case QUIT: // this is q        result        break    case HElP: // this is ?, this show info for the Operations.        System.out.println("\n --Program Info for Operations--");        System.out.println("The + add the top two items, the - subtract the top item from the next item.");        System.out.println("The * multiply the top two items, the / integer divide the second item by the top item.");        System.out.println("The % find the integer remainder when dividing the second item by the top item.");        System.out.println("The m unary minus -- negate the top item, the r exchange the top two items");        System.out.println("The d duplicate top item on stack, the p print (to the screen) the top item");        System.out.println("The n will print and remove the top item, the f will print all the contents of the stack (leaving it intact) ");        System.out.println("The c will clear the stack, the ? or h will print a help message");        System.out.println("And the q will make you quit the program.");        break    } }

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

How to get my second switch operations to work.

import java.util.Stack;
import java.util.Scanner;

public class PostfixEvaluator {
  
   private final static char ADD = '+';
private final static char SUBTRACT = '-';
private final static char MULTIPLY = '*';
private final static char DIVIDE = '/';
private final static char MODULUS = '%';
private final static char NEGATIVE = 'm';
private final static char EXCHANGE = 'r';
private final static char DUPLICATE = 'd';
private final static char PRINT = 'p';
private final static char PRINT_AND_REMOVE = 'n';
private final static char PRINT_ALL = 'f';
private final static char CLEARall = 'c';
private final static char QUIT = 'q';
private final static char HElP = '?';
  
  
private Stack stack;
  
public PostfixEvaluator()
{
stack = new Stack();
}

public int evaluate(String expr)
{
int op1, op2, result = 0;
String token;
Scanner parser = new Scanner(expr);
while (parser.hasNext())
{
token = parser.next();
if (isOperator(token))
{
op2 = (stack.pop()).intValue();
op1 = (stack.pop()).intValue();
result = evaluateSingleOperator(token.charAt(0), op1, op2);
stack.push(new Integer(result));
}
if (isCommand(token));
evaluateother(token.charAt(0), op1, op2);
  
   }
else
stack.push(new Integer(Integer.parseInt(token)));
}
return result;
}
///////////////////////////////////////////////////////////////////////////////////
private boolean isOperator(String token)
{
       return (token.equals("+") || token.equals("-") ||token.equals("*") ||
               token.equals("/") || token.equals("%") || token.equals("m"));
}
  
private boolean isCommand(String token)
{
       return (token.equals("r") || token.equals("d") || token.equals("p") ||
               token.equals("n") || token.equals("f") || token.equals("c") ||
               token.equals("q") || token.equals("?"));
}
///////////////////////////////////////////////////////////////////////////////////
private int evaluateSingleOperator(char operation, int op1, int op2)
{
int result = 0;
  
switch (operation)
{
case ADD: // this is +
result = op1 + op2;
break;
case SUBTRACT: // this is -
result = op1 - op2;
break;
case MULTIPLY: // this is *
result = op1 * op2;
break;
case DIVIDE: // this is /
result = op1 / op2;
break;
case MODULUS: // this is %
   result = op1 % op2;
   break;
case NEGATIVE: // this is m
   int result = op1 * -op2;
   break;
}
return result;
}
  
private void evaluateOtherOperator(char commmand, int op1, int op2)
{
   int reslut = 0;
  
   switch (operation) // This is second switch (operation)
   {
   case EXCHANGE: // this is r
       result =
       break
   case DUPLICATE: // this is d
       result
       break
   case PRINT: // this is p
       result
       break
   case PRINT_AND_REMOVE: // this is n
      
       break
   case PRINT_ALL: // this is f
       System.out.println(stack)
       break
   case CLEARall: // this is c
       stack.clear();
       break
   case QUIT: // this is q
       result
       break
   case HElP: // this is ?, this show info for the Operations.
       System.out.println("\n --Program Info for Operations--");
       System.out.println("The + add the top two items, the - subtract the top item from the next item.");
       System.out.println("The * multiply the top two items, the / integer divide the second item by the top item.");
       System.out.println("The % find the integer remainder when dividing the second item by the top item.");
       System.out.println("The m unary minus -- negate the top item, the r exchange the top two items");
       System.out.println("The d duplicate top item on stack, the p print (to the screen) the top item");
       System.out.println("The n will print and remove the top item, the f will print all the contents of the stack (leaving it intact) ");
       System.out.println("The c will clear the stack, the ? or h will print a help message");
       System.out.println("And the q will make you quit the program.");
       break
   }
}
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
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