reyarita 0 Light Poster

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

guys
i need your help.
i admit i really have a little about java.

i have my code but i doubt it, it really not follow the algorithm above.

heres my code

import java.util.*;
public class fixedpartition
{
    static Scanner rey=new Scanner(System.in);
    public static void main(String[]args)
    {

        int choose;

        try
        {
            for(int i=0;i<2;i++)
            {
                System.out.println();
                System.out.println("Preparing data...............\n\n");
                Thread.sleep(1000);
            }
        }
        catch(InterruptedException e)
        {
        }




        System.out.println("*** CHOOSE WHAT OPERATION DO YOU WANT ***\n\n");
        System.out.println("1 ------------------------>  Fixed partition\n\n");
        System.out.println("2 ------------------------>  Best Fit\n\n");
        System.out.println("3 ------------------------>  First Fit\n\n");


        System.out.print("Enter your choice:\t");
        choose=rey.nextInt();
        System.out.println();

        switch(choose)
        {
            case 1:
            {
                int[]partition={150,50,40,100};
                int job_size;
                int counter = 0;
                int number_of_paritions_in_Memory;
                int[] memory_partition_size = new int[partition.length];


                System.out.print("Partition Size      \t\t    Job Size    \t\t   Status\n");
                System.out.println("-------------------------------------------------------------------------------");
                System.out.println("   150    \t\t\t                                   FREE   ");
                System.out.println("   50    \t\t\t                                   FREE   ");
                System.out.println("   40    \t\t\t                                   FREE   ");
                System.out.println("   100    \t\t\t                                   FREE  \n\n ");
                System.out.println();

                try
                {
                    for(int i=0;i<2;i++)
                    {
                        System.out.println("Loading...............\n\n");
                        Thread.sleep(1000);
                    }
                }
                catch(InterruptedException e)
                {
                }
                System.out.print("Enter job size requested:\t");
                job_size=rey.nextInt();
                System.out.println();
                number_of_paritions_in_Memory=4;

                if(job_size>partition[0])
                {
                    System.out.println("Job Size is to large\n\n");

                    try
                    {
                        for(int i=0;i<2;i++)
                        {
                            System.out.println("Job Rejected...............\n\n");
                            Thread.sleep(1000);
                        }
                    }
                    catch(InterruptedException e)
                    {
                    }

                }
                else
                {
                    counter=1;
                    number_of_paritions_in_Memory=4;
                    System.out.println("The counter was set to:\t"+counter);
                    System.out.println("The number of partitions in memory: \t"+number_of_paritions_in_Memory);
                    //counter=0;

                    do
                    {
                        //if(job_size>partition[0])
                        if(job_size>partition[0])
                        //if(job_size>partition[counter])
                        {
                            //counter=counter+1;
                        }
                        else
                        {
                            //if(memory_partition_size[counter] == 0)
                            if(partition[counter] == 0)
                            //if(partition[counter] == 0)
                            {
                                partition[counter] = job_size;
                                System.out.println("Job Size : " + job_size);
                                /*System.out.print("Partition Size      \t\t    Job Size    \t\t   Status\n");
                                System.out.println("-------------------------------------------------------------------------------");
                                System.out.println("   150    \t\t\t         "+job_size+"                    BUSY   ");
                                System.out.println("   50    \t\t\t                                   FREE   ");
                                System.out.println("   40    \t\t\t                                   FREE   ");
                                System.out.println("   100    \t\t\t                                   FREE  \n\n ");
                                System.out.println();*/

                            }
                            else
                                counter+=1;
                        }
                    }
                    //while(counter<partition.length);
                    while(counter<memory_partition_size.length);

                }

                /*
                System.out.print("Enter next job size requested:\t");
                job_size=rey.nextInt();
                System.out.println();

                if(job_size>partition[1])
                {
                    System.out.println("Job Size is to large\n\n");

                    try
                    {
                        for(int i=0;i<2;i++)
                        {
                            System.out.println("Job Rejected...............\n\n");
                            Thread.sleep(1000);
                        }
                    }
                    catch(InterruptedException e)
                    {
                    }
                }

                System.out.print("Enter next job size requested:\t");
                job_size=rey.nextInt();
                System.out.println();

                if(job_size>partition[2])
                {
                    System.out.println("Job Size is to large\n\n");

                    try
                    {
                        for(int i=0;i<2;i++)
                        {
                            System.out.println("Job Rejected...............\n\n");
                            Thread.sleep(1000);
                        }
                    }
                    catch(InterruptedException e)
                    {
                    }
                }

                System.out.print("Enter next job size requested:\t");
                job_size=rey.nextInt();
                System.out.println();

                if(job_size>partition[3])
                {
                    System.out.println("Job Size is to large\n\n");

                    try
                    {
                        for(int i=0;i<2;i++)
                        {
                            System.out.println("Job Rejected...............\n\n");
                            Thread.sleep(1000);
                        }
                    }
                    catch(InterruptedException e)
                    {
                    }
                }*/
            break;
            }
            default:
            {
                System.out.println("Invalid!!!");
            }
        }




    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.