Computer Science > STUDY GUIDE > Simulator java (All)

Simulator java

Document Content and Description Below

/** * A Simple class meant to run a basic simulation to calculate the average wait time for the * elevators in a building with given number of floors and elevators with a maximum of one person per... elevator * @author Ian Sutherland * M. T., USB ID #107418612 * <dt><b>Assignment:</b><dd> * Homework #4 for CSE 214, Spring 2010 * <dt><b>Date:</b><dd> * March 23th, 2010 */ public class Simulator { private static Elevator[] elevate; private static BooleanSource prob; private static int served; private static int totalWait; private static int time; private static boolean debug = false; /** * Runs a sumulation to calculate the average wait time. * @param probablity * the probablity that a request will be genereated (1-100) * @param floors * the floors in the building (greater than 1) * @param elevators * the number of elevators (greater than 1) * @param length * the length for the simulation (greater than 1) */ public static void simulate(double probablity,int floors,int elevators,int length) throws IllegalArgumentException{ if(probablity<0||1<probablity||floors<=1||elevators<1||length<1){ IllegalArgumentException iae = new IllegalArgumentException(); throw iae; } prob = new BooleanSource(probablity); elevate = new Elevator[elevators]; for(int i = 0; i<elevators; i++){ elevate[i] = new Elevator(); } time = 0; RequestQueue que = new RequestQueue(); while(time<length){ if(prob.requestArrived()){ Request enqueueTemp = new Request(floors); enqueueTemp.setTimeEntered(time); que.enqueue(enqueueTemp); if(debug){ System.out.println("Request from floor " + enqueueTemp.getSourceFloor()); } }if(!que.isEmpty()){ for(int i = 0; i<elevate.length; i++){ if(elevate[i].getElevatorState()==Elevator.IDLE){ if(!que.isEmpty()){ if(debug){ System.out.println("Elevator " + (i+1) +" took a request"); } elevate[i].setRequest(que.dequeue()); [Show More]

Last updated: 2 years ago

Preview 1 out of 3 pages

Buy Now

Instant download

We Accept:

We Accept
document-preview

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

We Accept

Reviews( 0 )

$7.00

Buy Now

We Accept:

We Accept

Instant download

Can't find what you want? Try our AI powered Search

117
0

Document information


Connected school, study & course


About the document


Uploaded On

Jul 22, 2021

Number of pages

3

Written in

Seller


seller-icon
d.occ

Member since 4 years

231 Documents Sold

Reviews Received
30
8
4
1
7
Additional information

This document has been written for:

Uploaded

Jul 22, 2021

Downloads

 0

Views

 117

Document Keyword Tags

Recommended For You

Get more on STUDY GUIDE »

$7.00
What is Scholarfriends

In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·