Guest User

PostfixCalculator

a guest
Sep 25th, 2025
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. protected void evaluateOperator(String operator){
  2. LinkedList<Double> result = new LinkedList<>();
  3. //Grabs the number of arguments the operator needs from the operatorMap
  4. for (int i = 0; i < operatorMap.get(operator).numArgs(); i++) {
  5. result.add(stack.pop());
  6. System.out.println(result.get(i));
  7. }
  8. stack.push(operatorMap.get(operator).eval(result));
  9. }
  10.  
  11.  
  12. public static class Add implements Operator {
  13. /**
  14. * @return
  15. */
  16. @Override
  17. public int numArgs() {
  18. return 2;
  19. }
  20.  
  21. @Override
  22. public double eval(List<Double> args) {
  23. return args.get(0) + args.get(1);
  24. }
  25. }
Tags: #Java
Advertisement
Add Comment
Please, Sign In to add comment