CODE FOR PRIORITY-TRAIN TICKET ALLOCATION | URDINESH

Software Programming, Tutorials, Interview Preparations,Stock Market,BSE/NSE, General informations

Tuesday, May 20, 2014

CODE FOR PRIORITY-TRAIN TICKET ALLOCATION



PROGRAM:

class Thread1 extends Thread
{
public void run()
{
for(int i=0;i<10;i++)
System.out.println("NORMAL CITIZEN "+i+"  Person");
}
}
class Thread2 extends Thread
{
public void run()
{
for(int i=1;i<=10;i++)
{
if(i==5)
setPriority(MAX_PRIORITY);
System.out.println("WOMAN"+i+"  Person");
}
}
}
class Thread3 extends Thread
{
public void run()
{
for(int i=1;i<=10;i++)
System.out.println("SENIOR CITIZEN "+i+"  Person");
}
}
class Testthread
{
public static void main(String a[])
{
System.out.println(“TRAIN TICKET RESERVATION ALLOTMENT”);
Thread1 t1=new Thread1();
Thread2 t2=new Thread2();
Thread3 t3=new Thread3();
Thread t0=Thread.currentThread();
t1.setPriority(t1.NORM_PRIORITY);
t3.setPriority(t1.getPriority()+3);
t1.start();
t2.start();
t3.start(); 
}
 }






OUTPUT:

TRAIN TICKET RESERVATION ALLOTMENT

SENIOR CITIZEN :1  Person
WOMAN :1  Person
SENIOR CITIZEN: 2  Person
WOMAN: 2  Person
SENIOR CITIZEN: 3  Person
WOMAN :3  Person
SENIOR CITIZEN :4 Person
NORMAL CITIZEN :0  Person
WOMAN :4  Person
SENIOR CITIZEN: 5  Person
NORMAL CITIZEN :1  Person
WOMAN :5  Person
SENIOR CITIZEN: 6  Person
NORMAL CITIZEN: 2  Person
WOMAN :6  Person
SENIOR CITIZEN :7  Person
NORMAL CITIZEN :3  Person
WOMAN : 7  Person
SENIOR CITIZEN: 8  Person
NORMAL CITIZEN :4  Person
WOMAN :8  Person
SENIOR CITIZEN: 9  Person
NORMAL CITIZEN :5  Person
WOMAN : 9  Person
SENIOR CITIZEN :10  Person
NORMAL CITIZEN : 6  Person
WOMAN : 10  Person
NORMAL CITIZEN : 7  Person
NORMAL CITIZEN : 8  Person
NORMAL CITIZEN : 9  Person

No comments:

Post a Comment

Thanks for your valuable comments

Followers