Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java WITH A SOURCE CODE OF BELOW 1.7 (classroom computers cannot support 1.7+) and the Stack Interface, create a postfix calculator that reads in

Using Java WITH A SOURCE CODE OF BELOW 1.7 (classroom computers cannot support 1.7+) and the Stack Interface,

create a postfix calculator that reads in the whole expression (5 6 + 8 3 - *) and evaluates it. This calculator should also accept multi-digit numbers. Use double instead of int

Sample expressions to use: Regular and postfix expressions should be the same exact expressions, I apologize if I converted to postfix incorrectly

Regular notation:

(55 - 2) + 4 * 6 / 2

(2 - 5) * 4

4 * 3 / 2.0 - 62

Postfix

55 2 - 4 6 * 2 / +

2 5 - 4 *

4 3 * 2.0 / 62 -

WHY SOURCE CODE BELOW 1.7?

image text in transcribed

8 import java. math. BigDecimal: 9 import java.util.ArrayDeque: 10 import java.util.ArrayList: 11 import java.util.Deque; 12 import java.util.List: 13 14 15 public class PostFixCalculator 16 17 18 19 20 21 private List expressionnew ArrayList ); private Deque Double> stacknew ArrayDeque O public PostFixCalculator (List postfix) (expression-postfix;) public BigDecimal result() 23 24 25 26 27 28 29 30 31 32 for (int i-0: i -expression.size) Hi) // Determine if current element is digit or not if (Character.isDigit (expression.get (i).charAt (0))) stack.addLast (Double.parseDouble (expression.get(i) else double tempResult 0; double temp: 34 35 36 37 38 39 40 41 42 43 switch (expression.get(i)) case "+":tempstack.removeLast(): tempResult-stack.removeLast) +temp: break; case "-":temp -stack.removeLast) tempResult-stack.removeLast() - temp: break 45 46 47 48 49 50 51 52 53 54 case "*": tempstack.removeLast() tempResult stack.removeLasttemp: break case "/": tempstack.removeLast( tempResult-stack.removeLast) / temp: break; 56 57 58 stack. addLast (tempResult) return new BigDecinal (stack.removeLast)).setScale(3, BigDecimal.ROUND_HALFUP) 60 61 ) Interactions Console Compiler Output 1 error found: File: D:\Users Error: Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted PostFixCalculator.java [line: 36]

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions