bully algorithm in java source code
#2

import java.util.*;
class Bully1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=0;
while(n==0)
{
System.out.println("enter number of processes");
n=sc.nextInt();
if(n==0)
System.out.println("dude, process cannot be 0 ");
}
int pid[]=new int[n];

for(int i=0;i<n;i++)
{
pid[i]=1;
}
/*for(int k:pid)
System.out.println(k);*/
int max=Max.max(pid,0);
int cord=max;
System.out.println(":cord"+(cord));



//crash-=1;
while(true)
{
System.out.println("enter option:\n1.crash a process\n2.revoke\n3.exit");
int choice =sc.nextInt();
switch(choice)
{
case 1:
System.out.println("enter process to be crash");
int crash=sc.nextInt();
try
{
if(pid[crash]==0)
{
System.out.println("process already crashed");
}
else
{
pid[crash]=0;
System.out.println("enter the process who will initiate election");
int start=sc.nextInt();
//revoke-=1;

if(pid[start]==0)
{
System.out.println("process dead");
continue;
}
else
{

System.out.println("nold coordinator :"+cord);

cord=Max.max(pid,start);
System.out.println("new coordinator :"+cord);




}
}
}
catch(ArrayIndexOutOfBoundsException d)
{
System.out.println("does not exist"+d);
}
catch(Exception e)
{
System.out.println(e);
}

break;
case 2:
try
{
System.out.println("enter process u want to revoke");
int revoke=sc.nextInt();
if(pid[revoke]==1)
{
System.out.println("dude,process already alive");
}
else
{
pid[revoke]=1;
if(cord<revoke)
cord=revoke;
System.out.println("new coordinator is "+cord);

}
}
catch(ArrayIndexOutOfBoundsException d)
{
System.out.println("does not exist"+d);
}
catch(Exception e)
{
System.out.println(e);
}
break;
case 3:
return;
default:System.out.println("wrong choice");
break;

}
}

}



}
class Max
{
public static int max(int pid[],int k)
{
int max=0;
for(int i=k;i<pid.length;i++)
{
System.out.println("message received by process"+i);
if(pid[i]==1)
{
max=i;
}
}
return max;
}
}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Tagged Pages: java program on bully election algorithm, election algorithm program in java, bully election algorithm in java, bully algorithm in java source code, program of buuly algorithm, bully election algorithm java code, http googleweblight com lite url http seminarprojects org t bully algorithm in java source code ei los2cg2l lc en in s 1 m 71,
Popular Searches: sata cord, bully election algorithm in java, bully election algorithm program in java, bully alogrithm, how to treat a bully, bully and lamport algorithm code in java, source code for bully algorithm in java,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Messages In This Thread
bully algorithm in java source code - by Guest - 20-03-2013, 11:32 AM
RE: bully algorithm in java source code - by Guest - 25-04-2015, 12:11 AM

Possibly Related Threads...
Thread Author Replies Views Last Post
  free download source code of online college magazine 5 18,655 29-06-2018, 10:09 AM
Last Post: Guest
  opengl source code for butterfly 3 3,343 14-05-2018, 08:57 AM
Last Post: Akshatha k
  ice cream parlour management system in vb source code 4 5,353 04-04-2018, 11:58 PM
Last Post: vprk77
  dwt code in java for image 2 6,477 24-03-2018, 10:06 PM
Last Post: Guest
  source code in php for online training and placement cell management 1 6,734 23-03-2018, 09:06 AM
Last Post: ritzi
  free download college website project in html with source code 2 4,698 24-02-2018, 10:46 AM
Last Post: Guest
  source code for hospital management system in jsp 4 1,988 13-01-2018, 10:51 AM
Last Post: dhanabhagya
  source code in c for dna cryptography in computer sc ppt 1 1,570 09-01-2018, 09:59 PM
Last Post: harshavarshinib
  to find whether a number is krishnamurthy number or not using java 1 11,315 01-01-2018, 11:39 AM
Last Post: dhanabhagya
  java programmings for bus ticket reservation source code 1 6,256 09-11-2017, 11:28 PM
Last Post: Ayushi Nagar

Forum Jump: