Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this part, you will first design using pseudo code two versions of arithmetic calculators. The first version will be based on the pseudo code

In this part, you will first design using pseudo code two versions of arithmetic calculators. The first version will be based on the pseudo code that uses two different stacks (Array Stack based and Linked list stack based). The second version must be completely based on recursion and must not use any stack (however, we know by now that recursion will implicitly use JVMs own stack as in regular function calls). You will implement the first version in Java. Your arithmetic calculators must read lines of text from a text file, where each line contains a syntactically correct arithmetic expression. Your output file must repeat the input line and print the computed result on the next line.

Your calculators must support the following operators on integers and observe the standard operator precedence as shown in the following (1 to 8: 1 is highest and 8 is lowest. Operators of same precedence are evaluated from left to right).

1. Parentheses (possibly nested ones): ( , ) Unary operators:

2. factorial: !

3. minus: - Binary operators:

power function: x^y.

operators: *, /

operators: +, -

operators: >, , , <

operators: ==, !=

As part of this programming assignment, you will do the following:

a) Design and submit the pseudo-code for both the versions of arithmetic calculator.

b) Implement a Java program for the first version. In your program, you will implement and use your own array-based stack (and not the built-in Java stack) of variable size based on the doubling strategy.

c) Briefly explain the time and memory complexity of both versions of your calculator. You can

write your answer in a separate file and submit it together with the other submissions.

d) Provide test logs for the first version for at least 20 different and sufficiently complex arithmetic expressions that use all types of operators (including parentheses) in varying

combinations.

public interface Stack { int size(); boolean isEmpty(); void push(E e); E top(); E pop(); } public static class ArrayStack implements Stack { public static final int CAPACITY = 100; private E[] data; private int t = -1; public ArrayStack() { this(CAPACITY); } public ArrayStack(int capacity) { data = (E[]) new Object[capacity]; } public int size() { return (t + 1); } public boolean isEmpty() { return (t == -1); } public void push(E e) throws IllegalStateException { if (size() == data.length) throw new IllegalStateException("Stack is full!"); data[++t] = e; } public E top() { if (isEmpty()) return null; return data[t]; } public E pop() { if (isEmpty()) return null; E answer = data[t]; data[t] = null; t--; return answer; } } 

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

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions