Question: so i have this method it's half written and i'm having a terrible time understanding how to complete the operands can someone help me complete

so i have this method it's half written and i'm having a terrible time understanding how to complete the operands can someone help me complete the rest of the switch cases for +, - , * , / in java

rivate static double calculateSpacedPostfix(String postfixSpaced) {

Scanner scan = new Scanner(postfixSpaced);

StackInterface operands = new LinkedStack<>();

while(scan.hasNext()) {

String token = scan.next();

switch(token) {

case "+":

double result = 0;

while(operands.peek() != null){

result += operands.pop();

}

break;

case "(":

break;

case ")":

break;

default:

double value = Double.parseDouble(token);

operands.push(value); // Put each operand on the stack

}

}

scan.close();

return 0;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!