Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.Create a Project2 class under the project package. 2.Create MyStack and MyQueue classes under the package. 3.In the Project2 class you will create a static

1.Create a Project2 class under the project package.

2.Create MyStack and MyQueue classes under the package.

3.In the Project2 class you will create a static void main() method. In this main method you will do the following:

a.Utilize the MyStack and MyQueue classes to convert infix expressions involve single digit integer number, +, -, *, /, %, and together with ( ) into postfix expressions then evaluate the postfix expressions.

b.The infix expressions are located in a file named COSC241_P2_Input.txt. Each line contains an infix expression (whitespaces and empty lines should be ignored.).

c.The corresponding postfix expressions and results should be written into a file named COSC241_P2_Output_.txt.

d.Sample input and output files are provided.

e.The sample input file is by no mean listing all testing cases. You have to add 5 additional testing cases to the input file to test your program completely.

The input and output files should be located in the folder where your project folder is located (i.e. these io files and your project folder are sitting next to each other). When you open files for read and write you cannot use an absolute file path but have to use a relative file path. For example:

Scanner input = new Scanner(newFile("./ COSC241_P2_Input.txt "));

// In writing out the output

File outFile = new File("./Project2Output.txt");

g.Your program must work with another input file given the same format as well.

/**************************************************************

The sample input, COSC241_P2_Input.txt, is below

3 + 4 * 5 ((3 + 4)) * 5 ((3 + 4) * 5 3 * (( 4+ 5) % 6) - 7 / 8 3 * (( 4+ 5) % 6) - 7 / 8 * 3 * (( 4+ 5) % 6) - 7 / 88

/*****************************************************************

The sample output, COSC241_P2_Output_.txt, is below

Original Infix: 3 + 4 * 5 Corresponding Postfix: 3 4 5 * + Evaluation Result: = 23 Original Infix: ( ( 3 + 4 ) ) * 5 Corresponding Postfix: 3 4 + 5 * Evaluation Result: = 35 Original Infix: ( ( 3 + 4 ) * 5 **Invalid expression** Original Infix: 3 * ( ( 4 + 5) % 6 ) - 7 / 8 Corresponding Postfix: 3 4 5 + 6 % * 7 8 / - Evaluation Result: = 9 Original Infix: 3 * (( 4+ 5) % 6) - 7 / 8 * **Invalid expression** Original Infix: 3 * (( 4+ 5) % 6) - 7 / 88 **Invalid expression* 

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago