In this project, you will be implementing a railroad yard

Added on - 19 Sep 2019

  • 2

    Pages

  • 974

    Words

  • 88

    Views

  • 0

    Downloads

Trusted by +2 million users,
1000+ happy students everyday
Showing pages 1 to 1 of 2 pages
In this project, you will be implementing a railroad yard simulation program. The user willprovide a set of incoming cars, and then a desired outgoing order. Your program willdetermine if the given incoming cars can be rearrangedto the desired outgoing order or not.[50 points]Background: This is an example of a control/management system: in order to deliver specificresources to specific destinations, we have to guarantee that those resources are available attheir destinations. Consider: the easiest car todetactfrom a train transporting materials is theback most one. Thus, it would ideal to arrange thetrain'scars in such a way that the order ofdestinations visited, matches the order of the cars. If the required car is in the middle of thetrain, there will be trouble! Our goal is to address this by trying to arrange the cars into theorder of the destinations they will visit ("desired outgoing order").Problem: Imagine that the rail yard looks like this:Incoming carsOutgoing cars (based on destinationorder)>----------------------------------------------------------------------------------->A B C D EE D C B A>-----------------------------\/----------------------------------->\/||||||||||----------------Waiting LineIn this example, the incoming cars come in the order E, D, C, B and A. The desired outgoingorder (since the track moves only to the right) is A, B, C, D and E. Our program considers thefirst 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 allthe others cars) as well as the incoming car each time. Again, E != A but also D != A, so Dgets put in the waiting line, blocking E in the process. This will continue until A is the only carleft in the incoming line, and it will be sent out. This leaves nothing incoming, but B would bethe 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 theoutput. An example that does NOT match is UGTA to AGTU. A, T and G would go into thewaiting line. U would be sent out, but then the next required outgoing car is T. There would benothing left in the incoming line, and the top car in the waiting line would be G. So, the matchfails.Program Features:1.You must take in incoming cars from the user until they input "DONE".2.You must take in outgoing cars from the user until they have given as many cars as they didin step 1.3.You must print out whether or not the given input cars can be matched to the given output.Java API Usage Requirements:You may import the following packages:Scanner, Stack, Queue,LinkedList. No otherpackages are allowed.
desklib-logo
You’re reading a preview
Preview Documents

To View Complete Document

Click the button to download
Subscribe to our plans

Download This Document