Highlights
Intoduction
You implemented a discrete-event simulation using C++ in assignment 2. In assignment 3 we’re continuing with the theme of simulations, but this time you’re going to be implementing something that more closely resembles a continuous simulation. We’re going to be simulating traffic in assignment 3. In assignment 3, you’re going to be building something that resembles a continuous simulation of traffic flow on a one-dimensional plane.
Description
Your program is going to simulate traffic moving along a one-dimensional plane. In other words: you’re going to be having vehicles driving down a single lane road where vehicles can’t pass other vehicles. Our goal is to make some observations about certain kinds of patterns that appear when traffic is flowing on a road.
Here’s a video describing the kinds of things we could make observations about when we’re simulating traffic:
Martin Treiber from the Institute for Traffic Econometrics, Modelling, and Statistics at Technische Universität Dresden has an excellent traffic simulator that you can play with to get an idea of the kinds of things we can simulate for roads.
Your simulation will be simple compared to either of the above examples. Your program will accept some inputs, but then otherwise work independently (no file input is required for this assignment).
Here’s an example of what running your program will look like:
The simulation
The simulation consists of two major parts:
1. A road
2. Vehicles on the road
Inputs and outputs
The inputs for this program are:
1. The total amount of time the simulation should run for (an integer).
2. The total number of spaces the road has (an integer).
3. The speed limit for the road (an integer)
Your simulation implementation should keep track of and print out the traffic flow: the number of vehicles that have successfully driven past the end of the road by the end of the simulation.
The road
Our hypothetical road has the following properties:
Vehicles on the road Each vehicle on the road has the following properties:
Implementation requirements
The primary goal of this assignment is to evaluate your ability to use and implement interfaces in Java. A simulation runner has been provided to you. Your task is to implement the interfaces that the simulation driver needs to run.
Editing provided code You have been provided with several .java files. You are forbidden from modifying any of the provided files with one exception: You must change the methods in Time DrivenSimulationMain that return instances of the interfaces in this simulation to return instances of your implementations of those interfaces.
For example, if you have written an implementation of the Queue interface that you’ve called MyQueue, you should change TimeDrivenSimulationMain#queue from:
Animation
The output from your simulator should be “animated”. You can “animate” text output on the command line using the carriage return character and temporarily sleeping. Here’s an example of an animated text output program in Java:
To animate your road, in the method that prints the state of your simulation you should:
1. Print out a carriage return character System.out.print('\r'); (not println).
2. Print out a single character for each position on the road, representing either the vehicle at that location on the road, or an empty road space (an underscore _). You should use System.out.print (not println).
Interfaces
Here is a list of the interfaces you need to write classes to implement (you must write classes that implements these interfaces):
You are not permitted at all to change the interfaces. The grading team will replace interface files you submit with the ones provided with the assignment.
This COMP2150 - IT Computer Science has been solved by our PhD Experts at My Uni Paper.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.