# Assignment #8 Solution

\$30.00

Category:

## Description

Objective: The goal of this assignment is to practice implementing stacks.

Background: A mathematician hires you to write a program that can compute some expressions written in postfix form.

Assignment:

Specific instructions are as follows:

1. Write a class for a stack using a linked list. The stack class must have the name GenericStack. You must write regular stack methods (e.g., createStack, isEmpty, push, pop, popAll, peek) in the GenericStack class. Stack content must be of Object type (that is, the stack can store any data type). Create any other class necessary for the linked list node.

1. Write a class named Calculator. The Calculator class is the only class that will contain the main method. The Calculator class will prompt for an input file and read the file line by line. Each line of the file will contain a postfix expression as an input. In the lecture session, we have already seen how we can compute a postfix expression using a stack. Use a GenericStack object to compute the value of each expression your program will read from the input file. The actual evaluation must be done in the Calculator class. GenericStack is the data structure that will be used to evaluate an expression. Report the result for each expression on the terminal. Some expressions may be incomplete; report an error for those expressions.

An example line from an input file is provided below.

6523+8*+3+*

If you compute (evaluate) this postfix expression, it will result in 288.

An example of an incomplete expression is as follows:

6523+8*+3+

You will not be able to complete the evaluation of this expression; you must report that the expression is incomplete.

Comment:

• Each operand and operator in an expression will be separated by spaces in the input file.