Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

978-0764535376

More Books

Students also viewed these Databases questions

Question

What is American Polity and Governance ?

Answered: 1 week ago

Question

What is Constitution, Political System and Public Policy? In India

Answered: 1 week ago

Question

What is Environment and Ecology? Explain with examples

Answered: 1 week ago

Question

Be familiar with the five basic ways to manage demand.

Answered: 1 week ago