Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this Java project, you will be implementing a rail road yard simulation program. The user will provide a set of incoming cars, and then

In this Java project, you will be implementing a rail road yard simulation program. The user will provide a set of incoming cars, and then a desired outgoing order. Your program will determine if the given incoming cars can be rearranged to the desired outgoing order or not.

Background: This is an example of a control/management system: in order to deliver specific resources to specific destinations, we have to guarantee that those resources are available at their destinations. Consider: the easiest car to distinct from a train transporting materials is the back most one. Thus, it would ideal to arrange the train's cars in such a way that the order of destinations visited, matches the order of the cars. If the required car is in the middle of the train, there will be trouble! Our goal is to address this by trying to arrange the cars into the order of the destinations they will visit ("desired outgoing order").

Problem: Incoming cars come in the order E, D, C, B and A. The desired outgoing order (since the track moves only to the right) is A, B, C, D and E. Our program considers the first incoming car, vs the desired outgoing car. Since E != A, E must go into the waiting line. Now our program will consider both the car at the top of the waiting line (since it is blocking all the others cars) as well as the incoming car each time. Again, E != A but also D != A, so D gets put in the waiting line, blocking E in the process. This will continue until A is the only car left in the incoming line, and it will be sent out. This leaves nothing incoming, but B would be the top car in the waiting line. Since B == B, B gets taken from the waiting line and sent out. This will repeat until all cars are gone, meaning the input was successfully matched to the output. An example that does NOT match is UGTA to AGTU. A, T and G would go into the waiting line. U would be sent out, but then the next required outgoing car is T. There would be nothing left in the incoming line, and the top car in the waiting line would be G. So, the match fails.

Program Features:

You must take in incoming cars from the user until they input "DONE".

You must take in outgoing cars from the user until they have given as many cars as they did in step 1.

You must print out whether or not the given input cars can be matched to the given output.

Requirements and Notes:

You must implement your own linked structure(s) for this. In addition, you may not import anything other than Scanner.

You may not ask the user to specify the number of cars ahead of time.

The user must provide at least one incoming car.

Print a message if they don't and then allow the user to type in incoming cars again.

The user should be allowed to type in anything as a car. An example of three incoming cars might be: A, honda, 10101

You may not reorder the incoming, outgoing or waiting line.

Cars cannot go from the waiting line back to the incoming line.

Sample Output: Please type in the order of incoming cars. Type DONE to stop.

A B C D E

DONE

Please provide the desired output order equal to your input.

C E D A B

---------------------------

The input was successfully matched to the output!

C E D A B

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago