answersLogoWhite

0


Best Answer

import java.util.*;

class Partition

{

private int partstart;

private int partend;

private int partsize;

private int prosssize;

private int pid;

//private int intfrag;

private boolean empty;

private Partition next;

Partition Head=null;

public void createDynamicPartitions(int totmem)

{

Partition p=new Partition();

p.partsize=totmem;

//p.prosssize=0;

p.pid=-1;

//p.intfrag=0;

p.empty=true;

p.next=null;

p.partstart=0;

p.partend=totmem-1;

Head=p;

memStatus();

}

private Partition selectFirstHole(int prsize)

{

Partition temp=Head,first=null;

while(temp != null)

{

if (temp.empty && temp.partsize >= prsize)

{

break;

}

temp=temp.next;

}

return first;

}

public void loadProcess(int pid,int prsize)

{

Partition hole=selectFirstHole(prsize);

if(hole null)

System.out.println("There is no Process with ID :"+dpid);

else

memStatus();

}

private void memStatus()

{

Partition temp=Head;

System.out.println("Current Memory Status");

// int totfrag=0;

while(temp != null)

{

if(temp.empty)

System.out.println(temp.partstart+"-"+temp.partend+" : is hole of size "+temp.partsize);

else

System.out.println(temp.partstart+"-"+temp.partend+" :Memory with Process ID "+temp.pid+" of size "+temp.partsize);

//totfrag=totfrag+temp.intfrag;

temp=temp.next;

}

//System.out.println("\n Total Internal Fragmentation : "+totfrag);

}

}

public class FirstFit

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter Total Memory size :");

int totmem=sc.nextInt();

//System.out.println("Enter number of partitions :");

//int numofpartions=sc.nextInt();

//creating partitions

Partition dp=new Partition();

dp.createDynamicPartitions(totmem);

while(true)

{

System.out.println("Menu");

System.out.println("1.Load Process");

System.out.println("2.Remove Process");

System.out.println("3.Exit");

System.out.println("Enter ur Choice : ");

int ch=sc.nextInt();

switch(ch)

{

case 1:

System.out.println("Enetr Process ID : ");

int pid=sc.nextInt();

System.out.println("Enetr Process size : ");

int prsize=sc.nextInt();

dp.loadProcess(pid,prsize);

break;

case 2:

System.out.println("Enetr Process ID : ");

int dpid=sc.nextInt();

dp.removeProcess(dpid);

break;

case 3:

System.exit(0);

//break;

default:

System.out.println("*** Wrong Choice ***\n Choice must be in b/w 1- 3");

}

}

}

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Java code to implement the the first fit algorithm?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

C code to implement the file allocation algorithm?

yes we can do it,in c


Java source code for median filter algorithm?

research is going on to develop a source code for median filtering using java


What is the difference between an algorithm and java code?

In Java programming language, an algorithm refers to a sequence of instructions that have been specified to undertake a particular task within a certain time. An algorithm can take no or several inputs but will generate at least one output.


How do you create a simple decipher code in java?

decipher code depends upon the algorithm you used to make them. there are no general methods.


Implement the Dijkstras shortest path routing algorithm and submit the code listing with proper documentation?

#include


Where can one find out how to implement threads using Java?

You can find out how to implement threads using Java through Stacker Overflow, Java Script Source, Java Code Geeks, Free Programming Resources and other websites. There are also tutorials on college sites as well as Youtube.


How do i get source code for bide algoritham?

You can get the Java source code for the BIDE data mining algorithm here : (link moved to link section) It is an open-source data mining framework that includes the BIDE algorithm


In the first step of the Java hybrid compilation process Java program code is converted into an intermediate format called .?

Java byte code.


How is decoupling achieved in Java programs?

Decoupling is achieved in Java programs through the parser code. To debug the decoupling achieved in Java, run the source code over the parser code first.


How do you code java?

First you have to learn it, then it should be easy to do that.


Executon steps in java?

First of all the compiler converts our source code into byte code ,this is done by "javac" compiler.then we use interpretor that is the"java interpretor" for making our byte code executed.thats y java is called as an compiled and interpred language.by that way our java program will be interpreted. First of all our source code vl b converted into byte code by da java compiler named "javac" ,then dt byte code vl be executed by da interpretor named "java" interpretor. These are execution steps in java dts y v call java as a compiled and interpreted language.


How do you do this java code?

You have to specify the task that you wish me to help you with the Java code.