⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bankline.java

📁 Java code Bankline to allocated the source for next
💻 JAVA
字号:
import miscLib.SimpleInput;
import miscLib.GenLib;


public class BankLine {

    public static void main(String[] args) {
    //ListQueue t = new ListQueue();
    ArrayQueue t = new ArrayQueue();
    int  code, time, count;
    int maxTime =100;// The number of one minute loops in the program
    int minTellers ; // The minimum number of tellers serving customers in a run
    int maxTellers ;// The maximum number of tellers serving customers in a run
    final int MAX_TELLERS = 10 ;// The maximum number of tellers available
    int minTellerTime ;// Minimum minutes to serve a customer per teller
    int maxTellerTime ;// Maximum minutes to serve a customer per teller
    float chance; // Probability of customer entering the bank at each minute
   // int tellers [MAX_TELLERS] ;// Maximum of MAX_TELLERS tellers available
    int currentTime;// The current time from 1 to maxTime
    ArrayQueue waitLine ;// The waiting line of customers
    float averageLength ;// Average length (i.e. number of customers) of waiting line
    int maxLength ;// Maximum length (i.e. number of customers) of waiting line
    long totalWaitTime ;// Total time spent waiting by all customers
    int customerServed ;// Number of customers served
    float averageWaitTime ;// Average waiting time per customer
    long totalServiceTime ;// Total time spent serving all customers
    float averageServiceRate ;// Average serving time per customer
	Integer item;
	int TellerTime;

//---

//Read input parameters chance, minTellers, minTellerTime, maxTellerTime, and maxTime.
//Initialize the waiting line, the tellers, and the variables totalWaitTime, customerServed, averageLength,
//maxLength, and so on.

	minTellers = SimpleInput.getInteger("Enter total duration in minutes: ");
	minTellerTime = SimpleInput.getInteger("Enter event interval in minutes: ");
	maxTellerTime = SimpleInput.getInteger("Enter people count (lower bound): ");
	maxTime = SimpleInput.getInteger("Enter people count (upper bound): ");

	/*
	do {
	minTellerTime= 1 + (int)(Math.random() * 9);
	maxTellerTime = 1 + (int)(Math.random() * 9);
    } while(minTellerTime >= maxTellerTime);
	*/

	TellerTime = minTellerTime + (int)(Math.random() * maxTellerTime);
// TellerTime = GenLib.genInt(minTellerTime, maxTellerTime);
 chance= GenLib.genInt(1, 10);

//	count = 0;
		for (currentTime = 1; currentTime <= maxTime; currentTime++) {
			//code = GenLib.genInt(1, 10);	// customer arriving time

			//totalServiceTime = currentTime +(maxTellerTime-minTellerTime)+minTellerTime;	// event time
			if (time > maxTime) break;		// stop the loop if time expired
		//time=	currentTime;				// update the time for next event

			/*
			if (code != -1) { //it's an event, let's generate the count of the triplet
				if (code == 0) {
					count = GenLib.genInt(t.count_customer (), maxLength);	// how many people arrived
					System.out.println(count + " people arrived at time " + time);
				}
				else {
					//count = GenLib.genInt(minTellers, maxTellers);		// how many seats available
					System.out.println("Bus with " + count + " seats arrived at time " + time);
				}
		}
		*/

//				count=t.count_customer () +count  ;
//				 while (count-- > 0)

int [ ] array = new int  [Teller_State[Teller_number]];

int [ ] array = new int [start_time[Teller_number]];
int Teller_number;
	 t.enqueue (new Integer(chance));
			 t.addTellers( t.count_customer (),maxTeller);
for (int Teller_number = 0; Teller_number <= maxTeller; Teller_number++){
if (Teller_State[Teller_number] = 0){
	if (!t.empty()) {
			while (!t.empty ()) {
				item = (Integer) t.dequeue ();
				averageWaitTime += maxTime - item.intValue();
			}
			 System.out.println(" with average waiting time = " +
						averageWaitTime / ( t.count_customer () - people) + " minutes");
			}
		else {
				System.out.println(" with average waiting time = 0.0 minute");
		}
//item = (Integer) t.dequeue ();
Teller_State[Teller_number] = 1;
start_time[Teller_number] = currentTime;
}else
Teller_number++;
if (currentTime - start_time[Teller_number] = servicetime){
Teller_state[Teller_number] = 0;
customerServed++;
t.removeTellers( t.count_customer (),mintTeller);
totalServiceTime += serviceTime;
totalWaitTime += start_time-TellerTime;
}
}


//			totalServiceTime = currentTime +(maxTellerTime-minTellerTime)+minTellerTime;
//			else if (code == 1) {	// bus arrived and people got on bus from the queue
//			maxTellers++;
//				while ( (count > 0) && !t.empty ()) {
				//item = (Integer) t.dequeue ();
					//t.removeTellers( t.count_customer (),mintTeller);
			    	//int waitLine_temp = t.count_customer () +time - item.intValue();	// now, we know how long been waiting
					//waitLine_temp++;
					//count--;
			}
				//maxTellers += count;
	//	}


		// check # of people got on a bus
	if ( t.count_customer ()!= 0) {	// some people got on the bus
		System.out.println ( t.count_customer ()+ " people waited for " + averageWaitTime + " minutes, average waiting time = " +averageWaitTime/t.count_customer ()+ " minutes.");
	}
		else {	// no one got on the bus
			System.out.println ("0 people is waiting.");
		}

		// check # o buses passed the bus stop
		/*if (maxTellers != 0) {	// some buses did pass the bus stop
		System.out.println ("Number of buses passed the bus stop = " + maxTellers);
	System.out.println ("Average number of people got on a bus = " + t.count_customer ()/maxTellers);
		System.out.println ("Average number of vacant seats for a bus = " + maxTellers / maxTellers );
		}
		 else {	// no bus passed the bus stop
			System.out.println("0 bus passed the bus stop.");
		}
*/
//  t.addTellers( t.count_customer (), minTellers);

	// check # of people still waiting at the bus stop
//	System.out.print ("Number of people still waiting = " +	(t.count_customer () - averageLength )  );
/*
		if (!t.empty()) {
		while (!t.empty ()) {
			item = (Integer) t.dequeue ();
			averageWaitTime += maxTime - item.intValue();
		}
		 System.out.println(" with average waiting time = " +
					averageWaitTime / ( t.count_customer () - people) + " minutes");
		}
	else {
			System.out.println(" with average waiting time = 0.0 minute");
		}*/
System.out.println("Simulation time" + maxTime);
System.out.println("Minimum number of tellers" + minTellers);
System.out.println("Maximum number of tellers" + maxTellers);
System.out.println("Number of customer served " + customerServed);
System.out.println("Customer arrival rate:" + customerServed / maxTime);
System.out.println("Average service rate :"+totalServiceTime/customerServed);
System.out.println("Average waiting time:"+totalWaitTime/customerServed);
System.out.println("Average waiting line length:" ;





		System.exit(0);
}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -