GenericStack.java, Evaluator.java Assignment #9 Solution

$35.00 $24.00

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:   Write a class for a stack using a linked list. The stack class must have the…

You’ll get a: . zip file solution

 

 
Categorys:

Description

5/5 – (2 votes)

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.
  2. Write a class named Evaluator. The Evaluator class is the only class that will contain the main method. The Evaluator 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  Evaluator 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.

 

6 5 2 3 + 8 * + 3 + *

 

If you compute (evaluate) this postfix expression, it will result in 288. An example of an incomplete expression is as follows:

6 5 2 3 + 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.
  • You are not allowed to use java LinkedList class (that is, java.util.LinkedList).

You must use your own linked list node.

 

 

 

Deliverables: You  are  expected  to  submit  more  than  two  Java  files  (GenericStack.java, Evaluator.java, and any other file(s) to support your linked list) using Blackboard. Your TA will instruct you with further details.