Question
IN JAVA, MAKE THE CODE AS SIMPLE AS POSSIBLE, THANKS Each operand and operator in an expression will be separated by spaces in the input
IN JAVA, MAKE THE CODE AS SIMPLE AS POSSIBLE, THANKS
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.
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started