Modify the AWT model to: a) report out the largest number of customers enqueued
ID: 3817763 • Letter: M
Question
Modify the AWT model to:
a) report out the largest number of customers enqueued at the same time
b) assign the next arriving customer to a specific queue based on shortest finish time
c) provide a user interface control to allow user to select shortest finish time or shortest queue for assignments
create the program that is capable of answering these questions. with user inputed data such as arrival time, service time, number of customers, and ranges. then asks if the user wants to do it again with y/n:
determine a reasonable number of queues to use if there are 1000 customers and:
a) The inter-arrival time is 5 and the service time is 5
b) The inter-arrival time is 1 and the service time is 5
c) The inter-arrival time ranges from 0 to 20, and the service time ranges from 20 to 100
d) The inter-arrival time ranges from 0 to 2, and the service time ranges from 20 to 100
AWT model
import java.util.Random;
import java.util.Scanner;
public class AveragaWaitingTime {
static int Min(int b[], int a[], int tbt, int r, int n,int large[]) {
int j = 0;
int min = tbt;
int l=0;//finding larger number of process in queue
for (int i = n - 1; i >= 0; i--) {
if (b[i] < min && b[i] > 0 && r >= a[i]) {
min = b[i];
l++;
j = i;
}
}
if(large[0]
large[0]=l;
return j;
}
static int Shortesfinishtime(int n,int p[],int at[],int bt[],int bt2[],int wt[],int tat[])
{
int tbt = 0, large[] = {0};
for (int i = 0; i < n; i++) {
tbt = tbt + bt[i];
}
int time[] = new int[tbt];
int k = 0;
int q2 = 0;
System.out.println("Gantt Chart");
System.out.print("|");
//bt[0] = bt[0] - 1;
for (int i = 0; i < tbt; i++) {
int q = Min(bt, at, tbt, i, n,large);
if (q != q2) {
System.out.print(" p[" + p[q] + "] |");
time[k++] = i;
wt[q] = i;
tat[q] = i + bt[q];
}
bt[q] = bt[q] - 1;
q2 = q;
}
time[k] = tbt;
System.out.println();
System.out.print("0 ");
for (int i = 0; i <= k; i++) {
System.out.print(time[i] + " ");
}
double awt=0;//average waiting time
for(int i=0;i
{
awt=awt+wt[i];
}
awt=awt/n;
System.out.println(" AVERAGE WAITING TIME"+awt);
return large[0];//returning max number of process in queue at same time
}
static int shortestsizetime(int n,int process[],int ptime[],int wtime[])
{
int temp, total=0;
float avg=0;
for(int i=0;i
{
for(int j=i+1;j
if(ptime[i]>ptime[j])
{
temp = ptime[i];
ptime[i] = ptime[j];
ptime[j] = temp;
temp = process[i];
process[i] = process[j];
process[j] = temp;
}
}
}
wtime[0] = 0;
for(int i=1;i
{
wtime[i] = wtime[i-1]+ptime[i-1];
total = total + wtime[i];
}
avg = (float)total/n;
System.out.println("P_ID P_TIME W_TIME");
for(int i=0;i
{
System.out.println(process[i]+" "+ptime[i]+" "+wtime[i]);
}
System.out.println("Total Waiting Time: "+total);
System.out.println("Average Waiting Time: "+avg);
return n-1;
}
public static void main(String argv[])
{
//variable declaration
int n=100;//number of processes
int p[]=new int[n];
int a[]=new int[n];//to store arrival time of 100 processes
int b[]=new int[n];//to store service/burst/processing time of 100 processes
int b2[]=new int[n];//to store service/burst/processing time of 100 processes
int w[]=new int[n];//to store waiting time of 100 processes
int tat[]=new int[n];//to store turaround time of 100 processes
int i,j;
int quanta;//time slice for round robin
double round_robin,fcfs;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of processes");
n=sc.nextInt();
System.out.println("Enter the arrival time");
for(i=0;i<=n;i++);
{
a[i]= sc.nextInt();
}
System.out.println("Enter the Burst time");
for(i=0;i<=n;i++)
{
b[i]=sc.nextInt();
if(b[i]<0){ b[i]=b2[i]=-1*b[i];}
}
Random r= new Random(); //to generate random number
//generating randomly arrival time from 0 to 100
for(i=0;i
{
p[i]=i+1;
a[i]=r.nextInt()%101; //randomly number between 0 to 100 inclusive
}
//randomly burst/processing times from 0 to 100]
for(i=0;i
{
b[i]=(int)r.nextInt()%101; //random number from 0 to 100 inclusive
b2[i]=b2[i];
if(b[i]<0){ b[i]=b2[i]=-1*b[i];}
}
String ans1="";
do
{
int c;
String ans="Y";
//Scanner sc = new Scanner(System.in);
System.out.println("Enter 1: Shortestfinish time algorithm 2: Shortest size algorithm ");
c=sc.nextInt();
if(c==1)
{
System.out.println("Shortest finish time:");
//calling shortest finish time algorithm
System.out.println("Longest number of processes in queue:"+Shortesfinishtime(n,p,a,b,b2,w,tat));
}
else
{
System.out.println("Shortest size:");
//calling shortest size algorithm
System.out.println("Longest number of process in queue:"+shortestsizetime(n,p,b,w));
}
System.out.println("Do you want to continue(y/n)");
ans1 = sc.next();
}while(ans1.equals("y"));
}
}
It can be modified as much as needed
thank you. I really appreciate it
Explanation / Answer
# incorporate <iostream.h>
# incorporate <graphics.h>
# incorporate <conio.h>
# incorporate <math.h>
void show_screen( );
void Fill_rectangle(constint,constint,constint,constint);
void Rectangle(constint,constint,constint,constint);
void Line(constint,constint,constint,constint);
int fundamental( )
{
int driver=VGA;
int mode=VGAHI;
initgraph(&driver,&mode,"..\Bgi");
show_screen( );
for(int count_1=0;count_1<15;count_1++)
{
setcolor((count_1+1));
Rectangle((141+count_1),(69+count_1),(499-count_1),
(427-count_1));
}
setcolor(9);
for(int count_2=0;count_2<19;count_2++)
Rectangle((156+count_2),(84+count_2),(484-count_2),(412-count_2));
setcolor(12);
Rectangle((156+count_2),(84+count_2),(484-count_2),(412-count_2));
for(int count_3=0;count_3<9;count_3++)
{
Line((176+(count_3*36)),104,(176+(count_3*36)),392);
Line(176,(104+(36*count_3)),464,(104+(36*count_3)));
}
setcolor(15);
for(int count_4=0;count_4<8;count_4++)
{
for(int count_5=0;count_5<8;count_5++)
{
if(((count_5%2)+(count_4%2))==1)
Fill_rectangle((176+(count_5*36)),(104+(count_4*36)),
(212+(count_5*36)),(140+(count_4*36)));
}
}
roast English[8][3]={"H","G","F","E","D","C","B","A"};
roast Numbers[8][3]={"1","2","3","4","5","6","7","8"};
setcolor(15);
settextstyle(0,0,1);
for(int count_6=0;count_6<8;count_6++)
{
outtextxy(164,(120+(count_6*36)),Numbers[count_6]);
outtextxy((190+(count_6*36)),398,English[count_6]);
}
getch( );
return 0;
}
/*************************************************************************// - - Rectangle( ) - -/*************************************************************************/void Rectangle(constint x_1,constint y_1,constint x_2,constint y_2)
{
Line(x_1,y_1,x_2,y_1);
Line(x_2,y_1,x_2,y_2);
Line(x_2,y_2,x_1,y_2);
Line(x_1,y_2,x_1,y_1);
}
/*************************************************************************// - - Fill_rectangle( ) - -/*************************************************************************/void Fill_rectangle(constint x_1,constint y_1,constint x_2,constint y_2)
{
int y_min=((y_1>=y_2)?y_2:y_1);
int y_max=((y_1<=y_2)?y_2:y_1);
for(int count=(y_min+1);count<y_max;count++)
Line((x_1+1),count,(x_2-1),count);
}
/*************************************************************************// - - Line( ) - -/*************************************************************************/void Line(constint x_1,constint y_1,constint x_2,constint y_2)
{
int color=getcolor( );
int x1=x_1;
int y1=y_1;
int x2=x_2;
int y2=y_2;
if(x_1>x_2)
{
x1=x_2;
y1=y_2;
x2=x_1;
y2=y_1;
}
int dx=abs(x2-x1);
int dy=abs(y2-y1);
int inc_dec=((y2>=y1)?1:- 1);
if(dx>dy)
{
int two_dy=(2*dy);
int two_dy_dx=(2*(dy-dx));
int p=((2*dy)- dx);
int x=x1;
int y=y1;
putpixel(x,y,color);
while(x<x2)
{
x++;
if(p<0)
p+=two_dy;
else
{
y+=inc_dec;
p+=two_dy_dx;
}
putpixel(x,y,color);
}
}
else
{
int two_dx=(2*dx);
int two_dx_dy=(2*(dx-dy));
int p=((2*dx)- dy);
int x=x1;
int y=y1;
putpixel(x,y,color);
while(y!=y2)
{
y+=inc_dec;
if(p<0)
p+=two_dx;
else
{
x++;
p+=two_dx_dy;
}
putpixel(x,y,color);
}
}
}
/*************************************************************************// - - show_screen( ) - -/*************************************************************************/void show_screen( )
{
setfillstyle(1,1);
bar(262,26,365,38);
settextstyle(0,0,1);
setcolor(15);
outtextxy(5,5,"******************************************************************************");
outtextxy(5,17,"*-**************************************************************************-*");
outtextxy(5,29,"* - - - - *");
outtextxy(5,41,"*-**************************************************************************-*");
outtextxy(5,53,"*-**************************************************************************-*");
setcolor(11);
outtextxy(270,29,"Chess Board");
setcolor(15);
for(int count=0;count<=30;count++)
outtextxy(5,(65+(count*12)),"* *-*");
outtextxy(5,438,"*-**************************************************************************-*");
outtextxy(5,450,"* - - - - *");
outtextxy(5,462,"******************************************************************************");
setcolor(12);
outtextxy(229,450,"Press any Key to exit.");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.