Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  naresh
Language: JAVA
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author AJAYKUMAR
 */
import java.io.*;
public class naresh{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n;
        System.out.println("Enter no of customer:");
        n=Integer.parseInt(br.readLine());
        int iait[]=new int[n];
        int ait[]=new int[n];
        int able_avail[]=new int[n];
        int baker_avail[]=new int[n];
        int st[]=new int[n];
        int st_able[]=new int[n];
        int st_baker[]=new int[n];
        int tsb[]=new int[n];
        int able_sct[]=new int[n];
        int baker_sct[]=new int[n];
        int caller_delay[]=new int[n];
        int rait[]=new int[n];
        int rst_able[]=new int[n];
        int rst_baker[]=new int[n];
        String server_choosen[]=new String[n];
        int timeinsys[]=new int[n];
        int idle_able[]=new int[n];
        int idle_baker[]=new int[n];
        
        int total_wt=0,total_st=0,total_tisys=0,wait_cust=0; 
        double avg_wt,prob_wt,avg_st,atba,avg_tisys;
        
        int baker_sct1, caller_delay1, rait1, rst_able1, rst_baker1;
        int iait1,ait1,able_avail1,tsb1,able_sct1,baker_avail1;
        
        for(int i = 1;i<n;i++){
            if(i==0)
            rait[i] = 0;
            else{
            rait1 = (int)(Math.random()*99);
            rait[i] = rait1;
                }
            }
//generating of rst_able
        for(int i=0;i<n;i++)
        {
            rst_able1= (int)(Math.random()*99+1);
            rst_able[i] = rst_able1;
        }
//generating of rst_baker
        for(int i=0;i<n;i++)
        {
            rst_baker1= (int)(Math.random()*99+1);
            rst_baker[i] = rst_baker1;
        }
//generating iait
         for(int i=0;i<n;i++)
         {
             if(i==0)
                 iait[i]=0;
             else{
             if(rait[i]>0&&rait[i]<=25)
                 iait[i]=1;
             else if(rait[i]>25&&rait[i]<=65)
                 iait[i]=2;
             else if(rait[i]>65&&rait[i]<=85)
                 iait[i]=3;
             else if((rait[i]>85&&rait[i]<=99)||(rait[i]==0))
                 iait[i]=4;
             }
         }
//generating ait
         for(int i = 0;i<n;i++){
            if(i==0)
             ait[i] = 0;
            else{
             iait1 = ait[i - 1] +iait[i];
                ait[i]= iait1;
                }
            }
//generating st_able
         for(int i=0;i<n;i++)
         {
             if(rst_able[i]>0&&rst_able[i]<=30)
                 st_able[i]=2;
             else if(rst_able[i]>30&&rst_able[i]<=58)
                 st_able[i]=3;
             else if(rst_able[i]>58&&rst_able[i]<=83)
                 st_able[i]=4;
             else if((rst_able[i]>83&&rst_able[i]<=99)||(rst_able[i]==0))
                 st_able[i]=5;   
         }
//generating st_baker
         for(int i=0;i<n;i++)
         {
             if(rst_baker[i]>0&&rst_baker[i]<=35)
                 st_baker[i]=3;
             else if(rst_baker[i]>35&&rst_baker[i]<=60)
                 st_baker[i]=4;
             else if(rst_baker[i]>60&&rst_baker[i]<=80)
                 st_baker[i]=5;
             else if((rst_baker[i]>80&&rst_baker[i]<=99)||(rst_baker[i]==0))
                 st_baker[i]=6;   
         }
//generating table
         for(int i=0;i<n;i++)
         {
             if(i==0)
             {
                 able_avail[i]=0;
                 baker_avail[i]=0;
                 server_choosen[i]="able";
                 st[i]=st_able[i];
                 tsb[i]=0;
                 able_sct[i]=st[i];
                 baker_sct[i]=0;
                 caller_delay[i]=0;
                 timeinsys[i]=st[i];
             }
             else
             {
                 if(ait[i]>=able_sct[i-1])
                 {
                   able_avail[i]=able_sct[i-1];
                   server_choosen[i]="able";
                   st[i]=st_able[i];
                   tsb[i]=ait[i];
                   able_sct[i]=ait[i]+st[i];
                   caller_delay[i]=0;
                   timeinsys[i]=able_sct[i]-ait[i];
                   idle_able[i]=ait[i]-able_sct[i-1];
                   baker_avail[i]=baker_sct[i-1];
                   baker_sct[i]=baker_sct[i-1];
                 }
                 else if((ait[i]<able_sct[i-1])&&(ait[i]>=baker_sct[i-1]))
                 {
                     baker_avail[i]=baker_sct[i-1];
                     server_choosen[i]="baker";
                     st[i]=st_baker[i];
                     tsb[i]=ait[i];
                     baker_sct[i]=ait[i]+st[i];
                     caller_delay[i]=0;
                     timeinsys[i]=baker_sct[i]-ait[i];
                     idle_baker[i]=ait[i]-baker_sct[i-1];
                     able_avail[i]=able_sct[i-1];
                     able_sct[i]=able_sct[i-1];
                     
                 }
                 else if((ait[i]<able_sct[i-1])&&(ait[i]<baker_sct[i-1]))
                 {
                     wait_cust=wait_cust+1;
                     able_avail[i]=able_sct[i-1];
                     baker_avail[i]=baker_sct[i-1];
                     if(able_avail[i]>baker_avail[i])
                     {
                         server_choosen[i]="baker";
                         st[i]=st_baker[i];
                         tsb[i]=baker_avail[i];
                         baker_sct[i]=baker_avail[i]+st[i];
                         caller_delay[i]=baker_avail[i]-ait[i];
                         able_sct[i]=able_sct[i-1];
                         timeinsys[i]=baker_sct[i]-ait[i];
                     }
                     else{
                         server_choosen[i]="able";
                         st[i]=st_able[i];
                         tsb[i]=able_avail[i];
                         able_sct[i]=able_avail[i]+st[i];
                         caller_delay[i]=able_avail[i]-ait[i];
                         baker_sct[i]=baker_sct[i-1];
                         timeinsys[i]=able_sct[i]-ait[i];
                         }
                                      
                 }
             }
         }
        
       System.out.println("cust no\t"+"iait\t"+"ait\t"+"able_av\t"+"baker_av\t"+"ser_cho\t"+"ser_t\t"+"TSB\t"+"Able_sct\t"+"Baker_sct\t"+"delay\t"+"tis"); 
       for(int i=0;i<n;i++){
       total_wt+=caller_delay[i];
       total_st+=st[i];
       total_tisys+=timeinsys[i];
       System.out.println((i+1)+"\t"+iait[i]+"\t"+ait[i]+"\t   "+able_avail[i]+"\t  "+baker_avail[i]+"\t\t"+server_choosen[i]+"\t  "+st[i]+"\t"+tsb[i]+"\t   "+able_sct[i]+"\t\t   "+baker_sct[i]+"\t\t"+caller_delay[i]+"\t"+timeinsys[i]); 
       }
       
       avg_wt=(double)total_wt/n;
       prob_wt=(double)wait_cust/n;
       avg_st=(double)total_st/n;
       atba=(double)ait[n-1]/(n-1);
       avg_tisys=(double)total_tisys/n;
       System.out.println();
       System.out.println("Average Waiting time= "+avg_wt);
       System.out.println("probability(wait)= "+prob_wt);
       System.out.println("Average Service time= "+avg_st);
       System.out.println("Average time between arrivals= "+atba);
       System.out.println("Average time customer spends in system= "+avg_tisys);
       System.out.println();
       
       
    }
}
Comments: