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: 3 years ago

Preview 1 out of 3 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of Simulator java document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$7.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

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

147
0

Document information


Connected school, study & course


About the document


Uploaded On

Jul 22, 2021

Number of pages

3

Written in

All

Seller


Profile illustration for d.occ
d.occ

Member since 4 years

232 Documents Sold

Reviews Received
30
8
4
1
7
Additional information

This document has been written for:

Uploaded

Jul 22, 2021

Downloads

 0

Views

 147

Document Keyword Tags

Recommended For You

Get more on STUDY GUIDE »

$7.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

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·