Railroad Yard Simulation Program: Project

Added on - 20 Sep 2019

  • 4


  • 1034


  • 87


  • 0


Showing pages 1 to 2 of 4 pages
File Submission StandardsFor this final assignment you are asked to follow a restrict subset of the rulesgiven in theGoogle Java Style Guide(https://google.github.io/styleguide/javaguide.html). See below for specifics:1IntroductionSections: all.o2 Source filebasicsSections:2.1o3 Source filestructureSections:3.1*,3.2,3.3.1-2,3.4o4 FormattingSections:4.1,4.2,4.3,4.4,4.5,4.8.2,4.8.3,4.8.4,4.8.6,4.8.7*This is where you should include a description of your program as well asyour name.In this project, you will be implementing a railroad yard simulation program.The user will provide a set of incoming cars, and then a desired outgoingorder. Your program will determine if the given incoming cars can berearrangedto the desired outgoing order or not.Background: This is an example of a control/management system: in order todeliver specific resources to specific destinations, we have to guarantee thatthose resources are available at their destinations. Consider: the easiest cartodetactfrom a train transporting materials is the back most one. Thus, itwould 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 inthe middle of the train, there will be trouble! Our goal is to address this bytrying to arrange the cars into the order of the destinations they will visit("desired outgoing order").Problem: Imagine that the rail yard looks like this:
In this example, the incoming cars come in the order E, D, C, B and A. Thedesired outgoing order (since the track moves only to the right) is A, B, C, Dand E. Our program considers the first incoming car, vs the desired outgoingcar. Since E != A, E must go into the waiting line. Now our program willconsider both the car at the top of the waiting line (since it is blocking all theothers 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 willcontinue until A is the only car left in the incoming line, and it will be sentout. This leaves nothing incoming, but B would be the top car in the waitingline. Since B == B, B gets taken from the waiting line and sent out. This willrepeat until all cars are gone, meaning the input was successfully matchedto the output. An example that does NOT match is UGTA to AGTU. A, T and Gwould go into the waiting line. U would be sent out, but then the nextrequired 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: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 asmany cars as they did in step 1.3.You must print out whether or not the given input cars can be matchedto the given output.Java API Usage Requirements:You may import the following packages:Scanner, Stack,Queue,LinkedList. No other packages are allowed.ForLinkedList, you may only use it via Queue interface. Your programmust not use lists directly but instead rely on stacks and queues.When using the Queue collection, use only the following methods: add,remove, peek,isEmpty, size.When using the Stack collection, use only the following methods: push,pop, peek,isEmpty, size.Requirements and Notes:
You’re reading a preview

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document