Create a system to simulate vehicles at an intersection. Assume that there is one lane going in each of four directions, with stoplights facing each direction. Vary the arrival average of vehicles in each direction and the frequency of the light changes to view the “behavior” of the intersection.
PLEASE PROVIDE A JAVA CODE....
THANKS
Code:
EmptyCollectionException.java:
public class EmptyCollectionException extends RuntimeException
{
public EmptyCollectionException(String collection)
{
super("The " + collection + " is empty.");
}
}
LinkedQueue.java:
public class LinkedQueue<T> implements
QueueADT<T>
{
private int cnt;
private vecLinearNode<T> front, rear;
public LinkedQueue()
{
cnt = 0;
front = rear = null;
}
public void vecenqueue(T element)
{
vecLinearNode<T> unit = new
vecLinearNode<T>(element);
if (vecisEmpty())
front = unit;
else
rear.vecsetNext(unit);
rear = unit;
cnt++;
}
public T vecdequeue() throws EmptyCollectionException
{
if (vecisEmpty())
throw new EmptyCollectionException("queue");
T res = front.vecgetElement();
front = front.vecgetNext();
cnt--;
if (vecisEmpty())
rear = null;
return res;
}
public T vecfirst() throws EmptyCollectionException
{
if(!vecisEmpty())
return(front.vecgetElement());
else
throw new EmptyCollectionException("Nothing to peek");
}
public boolean vecisEmpty()
{
return(cnt == 0);
}
public int size()
{
return(cnt);
}
public String vectoString()
{
String qStr = "";
try
{
vecLinearNode<T> ele = front;
T elem2 = ele.vecgetElement();
for(int i = cnt; i > 0; i--)
{
qStr += (elem2);
if(i > 1)
{
qStr += "\n";
ele = ele.vecgetNext();
elem2 = ele.vecgetElement();
}
}
}
catch(NullPointerException e)
{
System.err.println("The tail is empty");
}
return qStr;
}
}
QueueADT.java:
public interface QueueADT<T>
{
public void vecenqueue(T element);
public T vecdequeue();
public T vecfirst();
public boolean vecisEmpty();
public String vectoString();
}
vecDriver.java:
public class vecDriver
{
public static void main (String[] args)
{
vecSimulator vecsimulator = new vecSimulator();
vecsimulator.vecSimulate();
}
}
vecLinearNode.java:
public class vecLinearNode<T>
{
private vecLinearNode<T> next;
private T element;
public vecLinearNode()
{
next = null;
element = null;
}
public vecLinearNode(T elem)
{
next = null;
element = elem;
}
public vecLinearNode<T> vecgetNext()
{
return next;
}
public void vecsetNext(vecLinearNode<T> node)
{
next = node;
}
public T vecgetElement()
{
return element;
}
public void vecsetElement(T elem)
{
element = elem;
}
}
vecSimulator.java:
import java.lang.Math;
import java.io.*;
import java.util.*;
import java.net.*;
import java.io.*;
public class vecSimulator
{
private LinkedQueue<vecVehicle> EL = new LinkedQueue<vecVehicle>();
private LinkedQueue<vecVehicle> ER = new LinkedQueue<vecVehicle>();
private LinkedQueue<vecVehicle> WL = new LinkedQueue<vecVehicle>();
private LinkedQueue<vecVehicle> WR = new LinkedQueue<vecVehicle>();
private LinkedQueue<vecVehicle> NL = new LinkedQueue<vecVehicle>();
private LinkedQueue<vecVehicle> NR = new LinkedQueue<vecVehicle>();
private LinkedQueue<vecVehicle> SCL = new LinkedQueue<vecVehicle>();
private LinkedQueue<vecVehicle> SCR = new LinkedQueue<vecVehicle>();
int t = 0;
int i = 0;
int v_num = 1;
FileWriter fw;
BufferedWriter bw;
PrintWriter pw;
// invoke the Constructor
public vecSimulator() {}
// write the result to file by calling other methods
public void vecSimulate()
{
try
{
fw = new FileWriter("output.txt");
bw = new BufferedWriter(fw);
pw = new PrintWriter(bw);
pw.print("+++++++++++++++++++++++++++++++++++++++++++++++ \n");
pw.print(" | | \n");
pw.print(" | AUTOMATIC TRAFFIC SIMULATION | \n");
pw.print(" | | \n");
pw.print("+++++++++++++++++++++++++++++++++++++++++++++++ \n");
pw.print("\n");
vecpopulate((int)(Math.random() * (13 - 7) + 7));
while(!vecqueuesEmpty())
{
pw.print("\n\n |||-------------------------------||| \n");
pw.print(" ||| TRAFFIC ALTERED ||| \n");
pw.print(" ||| N/S-bound is active |||\n");
pw.print(" |||-------------------------------||| \n");
vecmoveNorthSouth();
vecpopulate((int)(Math.random() * (16 - 8) + 8));
pw.println();
pw.print("\n\n |||-------------------------------||| \n");
pw.print(" ||| TRAFFIC ALTERED ||| \n");
pw.print(" ||| E/W-bound is active |||\n");
pw.print(" |||-------------------------------||| \n");
vecmoveEastWest();
vecpopulate((int)(Math.random() * (16 - 3) + 3));
pw.println();
}
pw.close();
}
catch(IOException e)
{
System.err.println("Error printing to file");
}
}
// intersection is populated here
private void vecpopulate(int randomNum)
{
int count = 0;
while (count < randomNum && v_num <=120)
{
vecVehicle car = new vecVehicle(v_num, t, t);
count++;
v_num++;
if (car.vecgetStreet() == vecVehicle.vecStreet.Main && car.vecgetDirection() == vecVehicle.vecDirection.E && car.vecgetLane() == vecVehicle.vecLane.Left)
EL.vecenqueue(car);
else if (car.vecgetStreet() == vecVehicle.vecStreet.Main && car.vecgetDirection() == vecVehicle.vecDirection.E && car.vecgetLane() == vecVehicle.vecLane.Right)
ER.vecenqueue(car);
else if (car.vecgetStreet() == vecVehicle.vecStreet.Main && car.vecgetDirection() == vecVehicle.vecDirection.W && car.vecgetLane() == vecVehicle.vecLane.Left)
WL.vecenqueue(car);
else if (car.vecgetStreet() == vecVehicle.vecStreet.Main && car.vecgetDirection() == vecVehicle.vecDirection.W && car.vecgetLane() == vecVehicle.vecLane.Right)
WR.vecenqueue(car);
else if (car.vecgetStreet() == vecVehicle.vecStreet.Church && car.vecgetDirection() == vecVehicle.vecDirection.N && car.vecgetLane() == vecVehicle.vecLane.Left)
NL.vecenqueue(car);
else if (car.vecgetStreet() == vecVehicle.vecStreet.Church && car.vecgetDirection() == vecVehicle.vecDirection.N && car.vecgetLane() == vecVehicle.vecLane.Right)
NR.vecenqueue(car);
else if (car.vecgetStreet() == vecVehicle.vecStreet.Church && car.vecgetDirection() == vecVehicle.vecDirection.S && car.vecgetLane() == vecVehicle.vecLane.Left)
SCL.vecenqueue(car);
else
SCR.vecenqueue(car);
}
}
// vehicle movement is tracked here
private void vecmoveNorthSouth()
{
int i = 0;
while (i < 2)
{
t+=3;
try
{
if (!NL.vecisEmpty())
{
vecVehicle car = new vecVehicle(0,0,0);
car = NL.vecdequeue();
car.vecsetDepartureTime(t);
pw.print(" ");
pw.println(car);
}
}
catch(EmptyCollectionException e) {}
try
{
if (!NR.vecisEmpty())
{
vecVehicle car = new vecVehicle(0,0,0);
car = NR.vecdequeue();
car.vecsetDepartureTime(t);
pw.print(" ");
pw.println(car);
}
}
catch(EmptyCollectionException e) {}
try
{
if (!SCL.vecisEmpty())
{
vecVehicle car = new vecVehicle(0,0,0);
car = SCL.vecdequeue();
car.vecsetDepartureTime(t);
pw.print(" ");
pw.println(car);
}
}
catch(EmptyCollectionException e) {}
try
{
if (!SCR.vecisEmpty())
{
vecVehicle car = new vecVehicle(0,0,0);
car = SCR.vecdequeue();
car.vecsetDepartureTime(t);
pw.print(" ");
pw.println(car);
}
}
catch(EmptyCollectionException e) {}
i++;
}
}
// east to west movement
private void vecmoveEastWest()
{
int i = 0;
while (i < 3)
{
t+=3;
try
{
if (!EL.vecisEmpty())
{
vecVehicle car = new vecVehicle(0,0,0);
car = EL.vecdequeue();
car.vecsetDepartureTime(t);
pw.print(" ");
pw.println(car);
}
}
catch(EmptyCollectionException e) {}
try
{
if (!ER.vecisEmpty())
{
vecVehicle car = new vecVehicle(0,0,0);
car = ER.vecdequeue();
car.vecsetDepartureTime(t);
pw.print(" ");
pw.println(car);
}
}
catch(EmptyCollectionException e) {}
try
{
if (!WL.vecisEmpty())
{
vecVehicle car = new vecVehicle(0,0,0);
car = WL.vecdequeue();
car.vecsetDepartureTime(t);
pw.print(" ");
pw.println(car);
}
}
catch(EmptyCollectionException e) {}
try
{
if (!WR.vecisEmpty())
{
vecVehicle car = new vecVehicle(0,0,0);
car = WR.vecdequeue();
car.vecsetDepartureTime(t);
pw.print(" ");
pw.println(car);
}
}
catch(EmptyCollectionException e) {}
i++;
}
}
// clears the queue
private boolean vecqueuesEmpty()
{
boolean empty;
empty = EL.vecisEmpty();
if(empty)
empty = ER.vecisEmpty();
if(empty)
empty = WL.vecisEmpty();
if(empty)
empty = WR.vecisEmpty();
if(empty)
empty = NL.vecisEmpty();
if(empty)
empty = NR.vecisEmpty();
if(empty)
empty = SCL.vecisEmpty();
if(empty)
empty = SCR.vecisEmpty();
return empty;
}
}
vecVehicle.java:
public class vecVehicle
{
public enum vecDirection{N, E, S, W};
public enum vecStreet{Main, Church};
public enum vecLane{Left, Right};
private int vehicleNumber;
private int arrivalTime;
private int departureTime;
private vecStreet street;
private vecDirection direction;
private vecLane lane;
private String bound;
private String continuation;
// call the Constructor
public vecVehicle (int vehicleNum, int aTime, int dTime)
{
vehicleNumber = vehicleNum;
arrivalTime = aTime;
departureTime = dTime;
direction = vecrandomDirection();
street = vecrandomStreet();
lane = vecrandomLane();
}
// randomly assign the direction
public vecDirection vecrandomDirection()
{
int dirIndicator = (int)(Math.random() * (4 - 0) + 0);
if(dirIndicator == 1)
direction = vecDirection.N;
else if(dirIndicator == 2)
direction = vecDirection.E;
else if(dirIndicator == 3)
direction = vecDirection.S;
else
direction = vecDirection.W;
return direction;
}
// determine the street randomly
public vecStreet vecrandomStreet()
{
if(direction == vecDirection.N || direction ==
vecDirection.S)
{
street = vecStreet.Church;
}
else
street = vecStreet.Main;
return street;
}
// assign vehicles randomly in lanes
public vecLane vecrandomLane()
{
int laneIndicator = (int)(Math.random() * (2 - 0) + 0);
if (laneIndicator ==1)
lane =vecLane.Left;
else
lane = vecLane.Right;
return lane;
}
// to get the direction
public vecDirection vecgetDirection()
{
return direction;
}
// view the street of a vehicle.
public vecStreet vecgetStreet()
{
return street;
}
// view from which lane the vehicle came.
public vecLane vecgetLane()
{
return lane;
}
// set the departure of vehicles in lanes.
public void vecsetDepartureTime(int time)
{
departureTime = time;
}
// get vehicle number.
public int vecgetVehicleNumber()
{
return vehicleNumber;
}
// associate the direction
public String vecgetBound()
{
if (direction == vecDirection.S)
return "southbound";
else if (direction == vecDirection.N)
return "northbound";
else if (direction == vecDirection.W)
return "westbound";
else
return"eastbound";
}
// defines the continuation
private String vecgetContinuation()
{
if (lane == vecLane.Left)
return "continued straight";
else if (lane ==vecLane.Right && direction ==
vecDirection.S)
return "turned right and headed westbound";
else if (lane ==vecLane.Right && direction ==
vecDirection.N)
return "turned right and headed eastbound";
else if (lane ==vecLane.Right && direction ==
vecDirection.W)
return "turned right and headed northbound";
else
return "turned right and headed southbound";
}
// determine the time as required format
public String vectoString()
{
String waittime = String.format("%02d",(departureTime -
arrivalTime));
return "[Time " + String.format("%02d", departureTime) + "] Vehicle
#" + vehicleNumber + " (" + vecgetBound() + ") " +
vecgetContinuation() + ". Total wait time " + waittime + "
seconds.";
}
}


Create a system to simulate vehicles at an intersection. Assume that there is one lane going...
Please help with my car traffic simulator!
Code that I already have below, I do not know how to start it
off!
public class IntersectionSimulation
{
private final static int EAST_WEST_GREEN_TIME = 30 ;
private final static int[] NORTH_SOUTH_GREEN_TIMES = { 20, 24, 30, 42 } ;
private final static int[] CAR_INTERSECTION_RATES = { 3, 5, 10 } ;
private final static int[] CAR_QUEUEING_RATES = { 5, 10, 30 } ;
private final static int[] EXPERIMENT_DURATIONS = { 3*60, 5*60,...
Solve it for java
Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...
------------------------------------------------------------------------------------------------------------
CODE ALREADY HAVE
BELOW---------------------------------------------------------------------------------------
public class LinkedQueue<T> implements
QueueADT<T>
{
private int count;
private LinearNode<T> head;
private LinearNode<T> tail;
public LinkedQueue()
{
count = 0;
head = null;
tail = null;
}
@Override
public void enqueue(T element)
{
LinearNode<T> node = new
LinearNode<T> (element);
if(isEmpty())
head =
node;
else
...
Help with Data Science python notebook, Question 1 Create a function called vowel_parse() that takes a single string as input. This string is the name of the input directory. It returns a dictionary. This dictionary has keys that are the names of the individual input files. The dictionary values are the number of words in that file that have adjacent vowels ('aa', 'ae', 'oo', 'ia', etc.). Use a regular expression to find these, do not hard code every possible combination...
Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...
Read the attached article. Do you feel one style of banking
control is more stable than the other? Why? Does one banking method
minimize market volatility and risk better or is it just packaged
differently? Do you feel the US (Western) Banking system can better
control the patterns of behavior going forward that have caused
economic damage in the past? Should the Fed continue its stimulus
policy, reduce it or abandon it entirely (Google some recent
articles to research this)? (Please...
A: China's makhle owe the country as we environmental problems. One of the trip is the yearly due ons which beroes the country. They po niskot business hills of dollar and leave parts of the typened in yellow dist. The problem severe's even affecting China's bors as well as t housalds of kill s The duoen om Marin May. Stwins pick up dins from the vast desert and plains of the newestem China and Moegli. The dirt is the carried...
How can we assess whether a project is a success or a
failure?
This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...
Hello! Could you please write a 6 paragraph summary (5-6
sentences each paragraph) of the below? In the overview, if you
could please describe the information in detail. Please have
completed in 6 days if possible. Thank you!
In 50 Words Or LesS .6TOC combines lean Six Sigma (LSS) and the theory of constraints (TOC) for bottom-line benefits . The method's metrics pyramids and communi- cations allow organiza- tions to retain gains and monitor benefits. · 6TOC goes beyond fac-...
10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...