Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Grab an expression from the user and evaluate it. The expression can contain +-/*( ) The expression will not contain any spaces. All the numbers

Grab an expression from the user and evaluate it. The expression can contain +-/*( )

The expression will not contain any spaces. All the numbers will be single digit (between 0 and 9). No error checking is necessary.

Example:

Give me an expression: 2*(6-3)

What will be displayed on the screen

Postfix expression: 243-*

Answer: 6

Do not use any of the built-in stack functions. Convert to postfix and evaluate.

Here is a Q&A link to some of your possible questions. Please email me any further questions and I will update the google document with some helpful hints.

Can I use any of the predefined classes in the library for stacks and queues?

A: No, you have to write your own code for stacks and queues and nodes

Do I take the input from a file or from the keyboard

A: You would take the input from the keyboard

What will the input look like

A: You will take an infix expression. All the numbers will have a single digit. The only operators that you will be using are +,-, /, *

How many stacks and queues should I use?

A: For the conversion from infix to postfix you need one stack and one queue. The stack will be used to store the operators. The queue will be used to store what would usually be displayed on the screen which is the postfix expression. Both the stack and the queue will be storing chars.

For the evaluation, another stack will be used. This stack will be storing integers. As the evaluation is being done, it is possible for the numbers to go beyond a single digit and so char datatype would no longer make any sense

What should be the output of this program

A: this program should output the postfix expression on one line and the result of the evaluation on another line.

How many classes should I have?

A: You will have 5 classes. Node, Stack, Queue, Postfix and Driver. For your Node, Stack and Queue classes, you will not have any static methods or variables. For your Postfix and Driver classes you will not have any instance methods or variables.

Why is everything in the Postfix class static?

A: Since there will be only one expression and it doesnt need to interact with any other expression, we dont need to create any objects of type Postfix.

There will be a static method that takes an infix argument and converts it to postfix.

A static method that checks the precedence of the operators

A static method that evaluates the postfix expression

How does the precedence method in the Postfix class work?

A: It takes a character as an argument which will be an operator. The operators will be assigned a number based on their precedence. Here is a possible sample

= 1

( 2

+,- 3

*,/ 4

The method can return the precedence of the operator that is being passed into it.

What conditions do I need to consider for converting infix to postfix

A: There are 4 conditions: open parentheses, close parentheses, numbers and operators

What does the main method in the Driver class look like

A:

Grab an infix expression from the user,

call the convert method in the Postfix class and grab its return value which is a postfix expression.

Display postfix expression

Call the evaluate method in the Postfix class with the converted postfix expression as its argument.and return the result

Display the result

How do I turn in my assignment

A: Everything should be in a single file. There should be only one public class (Driver)

Please code this in Java and make sure it runs, pls show the output you get

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

Step: 3

blur-text-image

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago