COMP 2150 — Assignment 3COMP 2150— Assignment 3Term: Winter 2023 Due: March 29th, 2023 at 4:30pmCOMP 2150 — Assignment 3 Term: Winter 2023 Due: March 29th, 2023 at 4:30pmContentsIntroduction...

1 answer below »



The 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.














more detail please see attachment




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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Inputs and outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 The road . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Vehicles on the road . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Implementation requirements 5 Editing provided code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Test suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Submission requirements 7 Assessment 7 Programming standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Unit tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Learning outcomes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 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 or be 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 current 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 current speed is never negative). • Every vehicle has a “model”, a single character that’s randomly selected from the lower-case letters and numbers. "abcdefghijklmnopqrstuvwxyz0123456789"; • Every vehicle has a “behaviour”. Some vehicles are “nervous” and will randomly slow down or 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 road. 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 forbidden 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() { return new MyQueue(); } 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: 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/carriage_return comp 2150 — assignment 3 term: winter 2023 due: march 29th, 2023 at 4:30pm } catch (interruptedexception e) {} } 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 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): • 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/carriage_return="" comp="" 2150="" —="" assignment="" 3="" term:="" winter="" 2023="" due:="" march="" 29th,="" 2023="" at="" 4:30pm="" }="" catch="" (interruptedexception="" e)="" {}="" }="" 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="" 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 DayMar 28, 2023

Answer To: COMP 2150 — Assignment 3COMP 2150— Assignment 3Term: Winter 2023 Due: March 29th, 2023 at...

Aditi answered on Mar 28 2023
38 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