Question

In: Computer Science

Create a system to simulate vehicles at an intersection. Assume that there is one lane going...

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.

Solutions

Expert Solution

Answer : Given data

* Assume that there is one lane going in each of four directions, with stoplights facing each direction.

//Sample output

//Project structure

//Code to copy

package simulateVehicles;

public class VehiclesInQueue {

int vehicleNumber;

String typeOfVehicle;

/*Implementation of toString method */

public String toString(){

return vehicleNumber +" " +typeOfVehicle;

}

}

package simulateVehicles;

public class Lane {

VehiclesInQueue vehiclesList[];

int front,rear;

/*Implementation of Default constructor */

Lane(){

vehiclesList = null;

front = 0;

rear = 0;

}

/*Implementation of Parameterized constructor */

Lane(int sizeofQueue){

vehiclesList = new VehiclesInQueue[sizeofQueue];

front = 0;

rear = 0;

for(int i =0;i<sizeofQueue;i++){

vehiclesList[i] = new VehiclesInQueue();

}

}

/*Implementation of vehicleAdd method */

void vehicleAdd(int vehicleNumber,String typeOfVehicle){

if(rear == vehiclesList.length){

System.out.println("Lane is full! So wait with RED signal");

return;

}

vehiclesList[rear].vehicleNumber = vehicleNumber;

vehiclesList[rear].typeOfVehicle = typeOfVehicle;

rear++;

}

/*Implementation of vehicleRemove method */

void vehicleRemove(){

if(front == rear){

System.out.println("Lane is empty!");

return;

}

/*Removes front from the Lane */

System.out.println("Removed Vehicle is : "+vehiclesList[front++]);

}

public static void main(String[] args){

/*Declaration of Lane class object */

Lane laneObject;

laneObject = new Lane(5);

/*add the vehicles to lane */

laneObject.vehicleAdd(1, "2 Wheeler");

laneObject.vehicleAdd(2, "4 Wheeler");

laneObject.vehicleAdd(3, "4 Wheeler");

laneObject.vehicleAdd(4, "8 Wheeler");

laneObject.vehicleAdd(5, "2 Wheeler");

System.out.println("\n");

/*Display the vehicles from Lane */

for(int i =0;i<5;i++){

System.out.println("vehicles added at Lane = " +laneObject.toString());

}

System.out.println("\n");

/*remove vehicles from lane */

for(int j =0;j<5;j++){

laneObject.vehicleRemove();

}

_____________THE END_______________

}

}


Related Solutions

A left turn lane is to be designed at a signalized intersection to accommodate leftturning vehicles...
A left turn lane is to be designed at a signalized intersection to accommodate leftturning vehicles during the peak period of traffic. If the design peak hour volume for the left turn movement is 150 vehicles per hour and the red time interval per signal cycle for the left turn movement is 60 seconds. a) Compute the average number of left turn vehicle arrivals per red interval of each signal cycle during the design peak hour. b) Assume that left...
1. On one approach of an intersection with fixed time traffic signal, vehicles arrival rate is...
1. On one approach of an intersection with fixed time traffic signal, vehicles arrival rate is 600 vehicles per hour. The effective green time for this approach is 30 seconds, the saturation flow of this approach is 1800 vehicles per hour and the cycle time of the intersection is 80 seconds. a. Evaluate the performance of the signal design i.e. will all vehicles clear during the green time? b. Recommend the changes to the green time for this approach to...
Two vehicles are approaching an intersection. One is a 2300 kg pickup traveling at 13.0 m/s...
Two vehicles are approaching an intersection. One is a 2300 kg pickup traveling at 13.0 m/s from east to west (the ?x- direction), and the other is a 1300 kg sedan going from south to north (the +y?direction at 21.0 m/s ). Q1: Find the x -component of the net momentum of this system. Q2: Find the y-component of the net momentum of this system. Q3: What is the magnitude of the net momentum? Q4: What is the direction of...
A two-lane minor road intersects a two-lane major road at 90 degrees, forming a four-leg intersection...
A two-lane minor road intersects a two-lane major road at 90 degrees, forming a four-leg intersection with traffic on the minor road controlled by a yield sign. A building is located 40 ft from the minor road. If the speed limit were 45 mi/h on the major road and 25 mi/h on the minor road, determine the minimum distance that the building can be located from the centerline of the outside lane of the major street.
A 6-lane two-way arterial road has a maximum flow of 6,000 vehicles per hour on one...
A 6-lane two-way arterial road has a maximum flow of 6,000 vehicles per hour on one direction. It is operating at 3,600 vehicles per hour at time, t=0. A collision occurs, blocking the two lanes, and restricting the flow of the third lane to 1,800 vehicles per hour. After 45 minutes, the MMDA and police have cleared the incident and traffic returns to normal as soon as the queue has already dissipated. a. Determine the maximum length of queue that...
Assume the following happened: One of the stop signs at the intersection of two Coquitlam roads...
Assume the following happened: One of the stop signs at the intersection of two Coquitlam roads is knocked over on Saturday evening; The city Roads & Transportation Service (responsible for “signs down, missing or vandalized”) gets a call to their Engineering Customer Service very early on Sunday morning (so now they know the sign is down) but decides to wait until Monday morning to replace the sign, in order to save $1,250 overtime pay to its road crew; Sunday evening,...
For a particular intersection, it has been bserved that the rate of people going thorugh the...
For a particular intersection, it has been bserved that the rate of people going thorugh the intersection while talking on their cell phone follows a Poisson process with an average of 6 people talking on their cell ohone per minute. Let X = number of people talking on their cell phone while driving through this intersection every 5 minutes. What is the probability that the 15th person talking on their cell phone will be observed going through this intersection in...
Vehicles arrive at a signalized intersection at a uniform rate of 900 veh/hr. The saturation flow...
Vehicles arrive at a signalized intersection at a uniform rate of 900 veh/hr. The saturation flow rate for the intersection is 1200 veh/hr. However, a crash has reduced the saturation flow rate to only 300 veh/hr for a one-hour period. Assuming D/D/1 queuing, determine: a. How long will it take for the resulting queue to clear? (6 points) b. How much delay is experienced as compared to if the saturation flow rate had NOT been reduced? (6 points) c. What...
1- Assume that you are going to build up a model for a system where unit...
1- Assume that you are going to build up a model for a system where unit operation and unit processes are carried out. Explain the various steps involved in the process of model building for the system you have chosen.
A two-lane rural highway, four-leg intersection will have its stop control replaced by a signal control....
A two-lane rural highway, four-leg intersection will have its stop control replaced by a signal control. Compute the expected average total crash frequency (all types, all severities) after the change for the following conditions: 
 Expected average crash frequency before change: 23 total crashes/yr AADT on minor road: 1500 veh/day
 AADT on major road: 5000 veh/day 
 Please show all work and formulas used. Thanks! Submitting this again this the last person didn't even answer the question at all. Not sure what...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT