Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I've got a software engineering assignment that I'm struggling with and would love some help. If anyone could get me started with it it

Hi, I've got a software engineering assignment that I'm struggling with and would love some help. If anyone could get me started with it it would appreciated

Thanks!

Problem Description: Write a program, In2pJ, which reads in an infix expression from the console and outputs a postfix expression that can subsequently be processed by a simple interpreter. This output will be used in the next assignment to create a simple 4-function calculator, as outlined in the attached file. You are not being asked to do a full implementation of the calculator, only the first stage which converts an algebraic expression of the form 34 / 5 + 16 * 2 (infix) to postfix notation, which for this example is 34 5 / 16 2 * +.

Method:

You are to use the Shunting Yard algorithm, the simple version of which is described in the attached file, and uses 3 data structures: 2 queues for holding input and output and a stack for holding operators. One of the difficulties in writing this program is in parsing the input string and separating it into operators and operands. Fortunately Java provides the stringTokenizer class that makes this easy. You can look up how this works online. Here is a simple test program you might want to try.

import java.util.StringTokenizer; import acm.program.ConsoleProgram; public class TestParse extends ConsoleProgram { public void run() { String str = readLine("Enter string: "); StringTokenizer st = new StringTokenizer(str,"+-*/",true); while (st.hasMoreTokens()) { println("-->"+st.nextToken()); } } }

You need to devise an appropriate loop (hint, look at the while loop in the above example) that enqueues this data in the input queue. From here, implementation of the Shunting Yard program follows the recipe outlined in the notes (there also a lot of information available online). Once your program is running, run through each of the following test cases, saving the results to a file.

Your submission should consist of 5 files: 1. Stack.java - stack class 2. Queue.java - queue class 3. listNode.java - node object 4. In2pJ.java - program 5. In2pJ.txt - output

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions