
Originally Posted by
reyarita
ALGORITHM TO LOAD A JOB IN A FIXED PARTITION
1. Determine job's requested memory size
2. If job_size > size of largest partition
Then reject the job
print appropriate message to operator
go to step 1 to handle next job in line
else
continue with step 3
3. Set counter to 1
4. Do while counter <=number of partitions in memory
If job__size > memory_partition_size(counter)
Then counter=counter+1
Else
If memory_partition_size(counter)="free"
Then load job into memory_partition(counter)
change memory_partition_status(counter) to "busy"
go to step 1 to handle next job in line
Else
counter=counter+1
5. No partition available at this time, put job in waiting queue
6. Go to step 1 to handle next job in line
I have my code pero dili mao.
tabang ko nino!!!!
this is my code
import java.util.*;
public class Partitions
{
static final int p1=100;
static final int p2=250;
static final int p3=300;
static final int p4=400;
static Scanner rey=new Scanner(System.in);
public static void main(String[]args)
{
int choose;
try
{
for (int a=0; a<1;a++)
{
System.out.println();
System.out.print("Preparing..... \n");
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
}
try
{
for (int a=0; a<1;a++)
{
System.out.println();
System.out.print("Loading..... \n");
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
}
System.out.print("________________________________ ___\n");
System.out.println("| 1 ------------> Fixed Partition |");
System.out.println("| 2 ------------> Best Fit |");
System.out.println("| 3 ------------> First Fit |");
System.out.println("|_____________________________ ____|\n");
System.out.print("Enter your choice:\t");
choose=rey.nextInt();
System.out.println();
switch (choose)
{
case 1:
{
System.out.print("\nYou choose Fixed Partitions\n");
try
{
for (int a=0; a<2;a++)
{
System.out.println();
System.out.print("Loading..... \n\n\n");
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
}
int j1,j2,j3,j4;
System.out.print("PARTITION \t PARTITION SIZE \t ACCESS \t STATUS\n");
System.out.println("1 "+p1 +" \t FREE ");
System.out.println("2 "+p2 +" \t FREE ");
System.out.println("3 "+p3 +" \t FREE ");
System.out.println("4 "+p4 +" \t FREE ");
System.out.println("\n\n\n");
System.out.print("Enter job requested:\t");
j1=rey.nextInt();
System.out.println();
if(j1>p1)
{
System.out.println("The job size is greater than the partition\n\n");
try
{
for(int a=0;a<2;a++)
{
System.out.println("Job Rejected....\n");
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
}
System.out.print("PARTITION \t PARTITION SIZE \t ACCESS \t STATUS\n");
System.out.println("1 "+p1 +" \t FREE ");
System.out.println("2 "+p2 +" \t FREE ");
System.out.println("3 "+p3 +" \t FREE ");
System.out.println("4 "+p4 +" \t FREE ");
System.out.println("\n\n\n");
System.out.print("Enter next job requested:\t");
j2=rey.nextInt();
System.out.println();
}
else
{
int counter;
int memory_partition_size;
int number_of_partition_in_memory=4;
do
{
counter=1;
//System.out.print("Set counter to:\t"+ counter);
//System.out.println("\n\nThe number of partition in memory is:\t"+number_of_partition_in_memory);
memory_partition_size=p1;
}
while(counter<=number_of_partition_in_memory);
{
if(j1>memory_partition_size)
{
counter=counter+1;
}
else
{
if(j1<=memory_partition_size)
{
System.out.print("PARTITION \t PARTITION SIZE \t ACCESS \t STATUS\n");
System.out.println("1 "+p1 +" J1("+j1+") BUSY ");
System.out.println("2 "+p2 +" \t FREE ");
System.out.println("3 "+p3 +" \t FREE ");
System.out.println("4 "+p4 +" \t FREE ");
System.out.println("\n\n\n");
}
else
{
counter=counter+1;
}
}
}
}
break;
}
default:
{
System.out.print("Invalid!!!");
}
}
}
}