You are on page 1of 10

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package premulf;

import java.util.Scanner;

/**
*
* @author hp
*/
public class PreMulF {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// TODO code application logic here
Scanner console = new Scanner(System.in);

System.out.print("How many processess do you need to create? :: ");


int total_process = console.nextInt();

/* while(true)
{
if(total_process < 20)
{
System.out.println("minimum of 20 processess should be selected");
System.out.print("How many processess do you need to create? :: ");

total_process = console.nextInt();
}
else
break;
}*/
System.out.println("Total number of processess are :: " + total_process);

int[] pnumber = new int[total_process];


int[] arr_tim = new int[total_process];
int[] bst_tim = new int[total_process];
int[] wait_tim = new int[total_process];
int[] turn_tim = new int[total_process];
int[] resp_tim = new int[total_process];

arr_tim[0] = 0;
pnumber[0] = 0;
bst_tim[0] = 4 + (int) (Math.random() * 27);
for (int i = 1; i < total_process; i++) {
pnumber[i] = i;
bst_tim[i] = 4 + (int) (Math.random() * 27);
arr_tim[i] = arr_tim[i - 1] + (int) (Math.random() * bst_tim[i - 1]);
}
System.out.println("Process number

Arrival Time

Burst Time");

System.out.println("====================================
====================");
for (int i = 0; i < total_process; i++) {
System.out.printf("%-24d%-22d%-10d\n", pnumber[i], arr_tim[i],
bst_tim[i]);
}
System.out.println("Time

Description");

System.out.println("====================================
=====================");
//System.out.println("0
selected.");

ms

P0 is created. P0 enters Q0. P0 is

int curr_tim = 0;
int total_brst_tim = 0;
resp_tim[0] = 0;
//wait_tim[0] = 0;
for (int i = 0; i < total_process; i++) {
total_brst_tim += bst_tim[i];
}
int
pq0=0,pq1=0,pq2=0,pq0et=0,pq1et=0,pq2et=0,cepq0=0,cepq1=0,cepq2=0;
boolean q0alass=true,q1alass=true,q2alass=true;
while(curr_tim != total_brst_tim)
{
if(pq1 > 0 && q1alass == false)
{
if(pq1et == 0)
{
if(bst_tim[cepq1] == 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
System.out.println("P" + cepq1 + " is completed in Q1. ");
}
else if(bst_tim[cepq1] > 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
System.out.println("P" + cepq1 + " is Aged in Q1 and send to Q2.
");
pq2++;
}
pq1--;

cepq1++;
q1alass = true;
}
}
/*if(pq2 > 0 && q2alass == false)
{
if(pq2et == 0)
{
if(bst_tim[cepq2] == 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
System.out.println("P" + cepq2 + " is completed in Q2. ");
pq2--;
}
else if(bst_tim[cepq2] > 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
System.out.println("P" + cepq1 + " is Aged in Q2 and send to
back of Q2. ");
}
if(cepq2<total_process)
cepq2++;
else
cepq2 = 0;
q2alass = true;
}
}*/
for(int lc1 =0; lc1 < total_process; lc1++)
{
if(arr_tim[lc1] == curr_tim)
{
System.out.printf("%-5d%-9s", arr_tim[lc1], "ms");

System.out.println("P" + lc1 + " is created. " + "P" + lc1 + " enters


Q0.");
pq0++;
}
}
while(pq0 > 0)
{
if(q0alass)
{
if(bst_tim[cepq0] > 4){
pq0et = 4;
bst_tim[cepq0] -= 4;
q0alass = false;
}
else{
pq0et = bst_tim[cepq0];
bst_tim[cepq0] = 0;
q0alass = false;
}
}
if(pq0et == 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
if(bst_tim[cepq0] == 0)
{
System.out.println("P" + cepq0 + " is completed in Q0. ");
}
else
{
System.out.println("P" + cepq0 + " is Aged in Q0 and send to Q1.
");
pq1++;
}

pq0--;
cepq0++;
q0alass = true;
}
else
{
pq0et--;
break;
}
}
while(pq1 > 0 && pq0 <= 0)
{
if(q1alass)
{
if(bst_tim[cepq1] > 8){
pq1et = 8;
bst_tim[cepq1] -= 8;
q1alass = false;
}
else if(bst_tim[cepq1] > 0){
pq1et = bst_tim[cepq1];
bst_tim[cepq1] = 0;
q1alass = false;
}
else
cepq1++;
}
if(pq1et == 0)
{
if(bst_tim[cepq1] == 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");

System.out.println("P" + cepq1 + " is completed in Q1. ");


}
else if(bst_tim[cepq1] > 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
System.out.println("P" + cepq1 + " is Aged in Q1 and send to Q2.
");
pq2++;
}
pq1--;
cepq1++;
q1alass = true;
}
else
{
pq1et--;
break;
}
}
while(pq2 > 0 && pq0 <= 0 && pq1 <= 0)
{
/*if(q2alass)
{
if(bst_tim[cepq2] > 12){
pq2et = 12;
bst_tim[cepq2] -= 12;
q2alass = false;
}
else if(bst_tim[cepq2] > 0){
pq2et = bst_tim[cepq2];
bst_tim[cepq2] = 0;
q2alass = false;

}
else if(bst_tim[cepq2] == 0){
if(cepq2<total_process-1)
cepq2++;
else
cepq2 = 0;
}
}
if(pq2et == 0 && q2alass == false)
{
if(bst_tim[cepq2] == 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
System.out.println("P" + cepq2 + " is completed in Q2. ");
pq2--;
}
else if(bst_tim[cepq2] > 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
System.out.println("P" + cepq2 + " is Aged in Q2 and send to
back of Q2. ");
}
if(cepq2<total_process-1)
cepq2++;
else
cepq2 = 0;
q2alass = true;
}
else
{
pq2et--;
break;

}*/
if(q2alass)
{
if(bst_tim[cepq2] > 12){
pq2et = 12;
bst_tim[cepq2] -= 12;
q2alass = false;
}
else if(bst_tim[cepq2] > 0){
pq2et = bst_tim[cepq2];
bst_tim[cepq2] = 0;
q2alass = false;
}
else
cepq2++;
}
if(pq2et == 0 && q2alass == false)
{
if(bst_tim[cepq2] == 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
System.out.println("P" + cepq2 + " is completed in Q2. ");
}
else if(bst_tim[cepq2] > 0)
{
System.out.printf("%-5d%-9s", curr_tim, "ms");
System.out.println("P" + cepq2 + " is Aged in Q2 and send to Q2.
");
}
pq2--;
cepq2++;
q2alass = true;

}
else
{
pq2et--;
break;
}
}
curr_tim++;
}
}
}

You might also like