Program to implement Cafeteria problem in java


import java.io.*;
import java.util.*;
class cafe
{
public static void main(String args[])throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader bin=new BufferedReader(isr);
int i,j,k=0,kk,run,counter;
int n=6,m= 5,s=6;
double se[]=new double[10];
int seed=12345;
double r,iat=0,st=0,nat,wt=0,cwt;
double p[]={0.0,0.05,0.4,0.65,0.8,0.9,0.97,1.0};
double at[]={0,0.5,1,1.5,2,2.5,3};
double f[]={0,0.05,0.3,0.65,0.85,1.0};
double t[]={1,2,3,4,5};
Random randy = new Random(12345);

System.out.println("Enter the value of run:");
run=Integer.parseInt(bin.readLine());
for(j=0;j<=s;++j)
{

randy.nextInt(12345);
counter=0;
nat=0;
cwt=0;
for(i=1;i<=j;++i)
{
se[i]=0;
}
cwt=0;
counter=0;
for(counter=1;counter<=run;++counter)
{
r=randy.nextDouble()/32768.0;
for(i=0;i<=n;++i)
{
if(r>p[i] && r<=p[i+1])
iat=at[i];
}
r=randy.nextDouble()/32768.0;
for(i=0;i<=m;++i)
{
if(r>f[i]  && r<=f[i+1])
st=t[i];
}
nat=nat+iat;
double  min=99.9;
for(i=1;i<=j;++i)
{
if(se[i]<=min)
{
min=se[i];
k=i;
}
}
if(nat<=min )
{
se[k]=min+st;
wt=(float)min-nat;
}
else
se[k]=nat+st;
cwt=(float)cwt+wt;
}
System.out.println("server"+" "+" Total arrival" +" " +  "Average waiting time  ");
System.out.println(j+"     "+counter+"   "+(cwt/run)+"    ");
if((cwt/run)<=2)
break;
}

Program toimplement Single Channel Queue in C++

#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<iomanip.h>

void main()
{
clrscr();
int i,j,c,rart[20],rsrt[20],art[20],srt[20],srtb[20],srte[20],cuwq[20],cuss[20],idts[20];
float pa[9],ps[7],iart;
int wtime=0;
float wcust=0.0;
float tservice=0.0;
float tidle=0.0;
float time_arr=0.0;
float time_spent=0.0;
cout<<"Enter no of inter arrival times ( less than 8 minutes)";
cin>>iart;
pa[0]=0;ps[0]=0;
for(i=1;i<=iart;i++)
pa[i]=(float)((1/iart)*1000);

for(i=1;i<=6;i++)
{
cout<<"\nEnter probability for service time "<<i<<" minute";
cin>>ps[i];
ps[i]*=100;
}
cout<<"Enter number of customers (number should be less than 20)";
cin>>c;

PROGRAM TO TEST UNIFORMITY OF RANDOM NO in JAVA


import java.io.*;
import java.util.*;
class randomuni
{ 
  public static void main(String args[])throws IOException
  
  { int i,j;
    int r[]=new int[100];
    
    int arr1[]=new int[100];
    BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
    
    System.out.println("Random number generated using in built function ");
    Random randomGenerator = new Random();
    for (i = 0; i < 100; i++)
    {
      int randomInt = randomGenerator.nextInt(100);
      arr1[i]=randomInt;
      System.out.print(randomInt+" ");
    }

    System.out.println("\nRandom number generated using linear congruential method ");
    System.out.println("Enter the values of X0,a,c and m \n");
    int xo=Integer.parseInt(b.readLine());
    int a=Integer.parseInt(b.readLine());
    int c=Integer.parseInt(b.readLine());
    int m=Integer.parseInt(b.readLine());

    for(i=0;i<100;i++)
    {
    int rand=((a*xo+c)%m);
    r[i]=rand;
    System.out.print(r[i]+" ");
    xo=rand;
    }
    System.out.println("\nSelect any method to test uniformity--1.kolmogorav  2.chi square ");
    i=Integer.parseInt(b.readLine());
    switch(i)
    {
     case 1:double dplus,dminus,dplmax=0,dmimax=0,d,cv=0.410;
            for(i=0;i<99;i++)
            { for(j=i+1;j<100;j++)
              {  if(r[i]>r[j])
                 { int temp=r[i];
                   r[i]=r[j];
                   r[j]=temp; 
                 }
              }
            } 
 

0 comments :

Program to test Independency of RANDOM NO in JAVA

import java.io.*;
import java.util.*;
class randomind
{
  public static void main(String args[])throws IOException
 
  { int i,j;
    int r[]=new int[10];
    double u,var2,var,z,cv=1.96,n1=0,n2=0,mean=49.5;
    int run[]=new int[10];
    int ar=0;
    int arr1[]=new int[10];
    BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
   
    System.out.println("Random number generated using in built function ");
    Random randomGenerator = new Random();
    for (i = 0; i < 10; i++)
    {
      int randomInt = randomGenerator.nextInt(100);
      arr1[i]=randomInt;
      System.out.print(randomInt+" ");
    }

    System.out.println("\nRandom number generated using linear congruential method ");
    System.out.println("Enter the values of X0,a,c and m \n");
    int xo=Integer.parseInt(b.readLine());
    int a=Integer.parseInt(b.readLine());
    int c=Integer.parseInt(b.readLine());
    int m=Integer.parseInt(b.readLine());

Program to Generate RANDOM NO.s in JAVA

import java.io.*;
import java.util.*;
class randomgen
{ 
  public static void main(String args[])throws IOException
  { 
    int i;
    int r[]=new int[10];
    int arr1[]=new int[10];
    BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
    
    System.out.println("Random number generated using in built function ");
    Random randomGenerator = new Random();
    for (i = 0; i < 10; i++)
    {
      int randomInt = randomGenerator.nextInt(100);
      arr1[i]=randomInt;
      System.out.print(randomInt+" ");
    }
    System.out.println("\nRandom number generated using linear congruential method ");
    System.out.println("Enter the values of X0,a,c and m \n");
    int x=Integer.parseInt(b.readLine());
    int a=Integer.parseInt(b.readLine());
    int c=Integer.parseInt(b.readLine());
    int m=Integer.parseInt(b.readLine());
    for(i=0;i<10;i++)
    {
      int rand=((a*x+c)%m);
      r[i]=rand;
      System.out.print(r[i]+" ");
      x=rand;
    }
  }     
}

0 comments :