Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

COMP 2150 — Assignment 3 COMP 2150— Assignment 3 Term: Winter 2023 Due: March 29th, 2023 at 4:30pm COMP 2150 — Assignment 3 Term: Winter 2023 Due: March 29th, 2023 at 4:30pm Contents Introduction...

1 answer below »
COMP 2150 — Assignment 3
COMP 2150— Assignment 3
Term: Winter 2023 Due: March 29th, 2023 at 4:30pm
COMP 2150 — Assignment 3 Term: Winter 2023 Due: March 29th, 2023 at 4:30pm
Contents
Introduction 2
Description 2
The simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX3
Inputs and outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX3
The road . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX3
Vehicles on the road . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX4
Implementation requirements 5
Editing provided code . . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX5
Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX5
Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX6
Test suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX6
Submission requirements 7
Assessment 7
Programming standards . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX8
Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX8
Unit tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX8
Learning outcomes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XXXXXXXXXX9
1
COMP 2150 — Assignment 3 Term: Winter 2023 Due: March 29th, 2023 at 4:30pm
Introduction
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.
������ Learning outcomes
Assignment 3 is assessing you on the following outcomes from COMP 2150:
1. Force a class to implement abstract methods by having it implement an interface.
2. Use interfaces as variable types, parameter types, and return values.
3. Build classes that implement multiple interfaces at the same time.
Assignment 3 is also explicitly assessing you on one learning outcome from COMP 1020:
4. Compile and run a Java programwith multiple files located in the same directory.
Description
Your program is going to simulate trafficmoving 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 couldmake observations about whenwe’re simulating
traffic:
2
https:
en.wikipedia.org/wiki/Discrete-event_simulation
https:
en.wikipedia.org/wiki/Continuous_simulation
https:
www.youtube.com/watch?v=iHzzSao6ypE
COMP 2150 — Assignment 3 Term: Winter 2023 Due: March 29th, 2023 at 4:30pm
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 programwill accept
some inputs, but then otherwise work independently (no file input is required for this assignment).
Here’s an example of what running your programwill look like:
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
03:56 sample (main) ✗ java Main
COMP 2150 road simulator (hyper-realistic)
How long should this simulation run for? 100
How long should the road be? 100
What is the road's speed limit? 5
3__n__$_____________5_________e_________g_________f_____j____j_____^______________________i_________
The simulation
The simulation consists of twomajor 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:
• The road has a start and an end (the start is visually on the left, the end is visually on the right).
• All vehicles on the road start at the start (location 0) and drive toward the end of the road (all
vehicles on the road are driving in the same direction).
3
https:
www.mtreiber.de/index.html
http:
www.traffic-simulation.de
https:
asciinema.org/a/565241
COMP 2150 — Assignment 3 Term: Winter 2023 Due: March 29th, 2023 at 4:30pm
• The road is made up of 1-unit spaces, where each space can either be occupied by a vehicle o
e unoccupied (two vehicles cannot share a space, no crashing).
• The road has a speed limit. Vehicles on the road cannot drive faster than the posted speed limit.
Vehicles on the road
Each vehicle on the road has the following properties:
• A vehicle is stopped when it’s added to a road.
• A vehicle moves at each unit of time by increasing its cu
ent position on the road by the speed
that it’s travelling at (e.g., a vehicle moving at a velocity of 3 starting at position 4 will move to
position 7 on the road when it moves).
• A vehicle will increase its speed when it is able to (it will not crash into the vehicle in front of it; it
will not exceed the speed limit of the road).
• A vehicle will decrease its speed when it has to (if it doesn’t slow down before moving, it will
crash into the vehicle in front of it; vehicles should avoid crashing into the vehicle in front of
them by continually decreasing speed until it will not crash into the vehicle in front of it, possibly
coming to a full stop with a speed of 0).
• A vehicle will not go in reverse (its cu
ent speed is never negative).
• Every vehicle has a “model”, a single character that’s randomly selected from the lower-case
letters and numbers.
"abcdefghijklmnopqrstuvwxyz XXXXXXXXXX";
• Every vehicle has a “behaviour”. Some vehicles are “nervous” and will randomly slow down o
stop. Others are “not nervous” and will never slow down randomly.
– Whether a vehicle is nervous or not is determined when the vehicle is initially added to the
oad. If a vehicle is not nervous, it will never randomly slow down.
– A nervous vehicle should have its model be drawn from symbol characters:
"!@#$%^&*";
– Approximately 1 out of 10 vehicles is nervous (e.g., you generate random integers between
0 and 9, any time you generate a 0, then the vehicle is “nervous”).
– If a vehicle is nervous, it will randomly slow down approximately 25% of the times that it
moves (e.g., each time a nervous vehicle moves, you generate a random integer between 0
and 3, a nervous vehicle will slow down if the number is 0).
4
COMP 2150 — Assignment 3 Term: Winter 2023 Due: March 29th, 2023 at 4:30pm
– When a nervous vehicle slows down, it will slow down by a random amount up to and
including stopping entirely.
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 fo
idden frommodifying any of the pro-
vided files with one exception: You must change the methods in TimeDrivenSimulationMain
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:
public static Queue queue() {
throw new UnsupportedOperationException("");
}
to:
public static Queue queue() {
eturn new MyQueue();
}
Animation
The output from your simulator should be “animated”. You can “animate” text output on the command
line using the ca
iage return character and temporarily sleeping. Here’s an example of an animated
text output program in Java:
char[] symbols = new char[] {'-', '/', '|', '\\'};
for (int i = 0; i < 100; i++) {
System.out.printf("\r%c", symbols[i % symbols.length]);
try {
Thread.sleep(200);
sleep for 200 ms
5
https:
en.wikipedia.org/wiki/Ca
iage_return
COMP 2150 — Assignment 3 Term: Winter 2023 Due: March 29th, 2023 at 4:30pm
} catch (Inte
uptedException e) {}
}
To animate your road, in the method that prints the state of your simulation you should:
1. Print out a ca
iage 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 Sys-
tem.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):
Answered Same Day Mar 28, 2023

Solution

Aditi answered on Mar 28 2023
26 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here