Implementing a railroad yard simulation program

Assignment Help JAVA Programming
Reference no: EM131585886

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 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 detact 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: Imagine that the rail yard looks like this:
Incoming cars Outgoing cars (based on destination order)
>----------------------------------------------------------------------------------->
A B C D E E D C B A
>----------------------------- /----------------------------------->
/
| |
| |
| |
| |
| |
----------------
Waiting Line

In this example, the 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.
Java API Usage Requirements:
You may import the following packages: Scanner, Stack, Queue, LinkedList. No other packages are allowed.
For LinkedList, you may only use it via Queue interface. Your program must 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:
Don't use arrays to store trains and move cars. Use stack(s) and queue(s).
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.
"Cars" is a loose term. 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.
You do not need to verify that the user typed in the same outgoing items as incoming. (i.e. They said the only incoming car is A and the only outgoing one is B. Your program should report that it cannot be matched, but you do not need to display a special error message or anything else)

Make sure you test your program thoroughly. You are encouraged to use the provided examples, but you should verify that your program works with several of your own examples.

Attachment:- Railroad.rar

Reference no: EM131585886

Questions Cloud

Find a flow that achieves new upper bound : You'd like to download the six most recent episodes of the television show Exile on Eggs Isle.
What is price and output : The graph below depicts a Natural Monopoly. Say the government wanted to enforce an efficient (allocative efficient) outcome. What is price and output
Executives manage a product life cycle : What are ways marketing executives manage a product's life cycle? In what ways do pricing constraints impact price setting?
What are social factors that are greatest threat to health : What are the social factors that play a critical role in improving health? What are the social factors that are the greatest threat to health?
Implementing a railroad yard simulation program : Implementing a railroad yard simulation program. The user will provide a set of incoming cars, and then a desired outgoing order
Is it possible that first or second person is telling truth : Tragedy has occurred at the Lovely Estate (shown in Figure, and "James Bomb, the internationally known detective, former notary public.
Discuss a riot beginning in a commercial area of town : Considering Fiedler's and Hershey & Blanchard's Situational Leadership Theory, as CEO, which style would you use in the following situations
What are the returns to scale for this production function : What are the returns to scale for this production function? Suppose both K and L are flexible in the long run
Managing the berkshire hathaway investment fund : what has Warren Buffett’s the annual rate of return since he started managing the Berkshire Hathaway investment fund?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd