Object XMLDocument

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

PROGRAM: import java.io.*; import java.lang.

*; class pat { public int disp(int cn) { return(cn); } } class Patient extends Thread { Dentist m=new Dentist(); pat c=new pat(); public synchronized void run() { try { while(m.cnum<m.n) { int t=c.disp(m.cnum++); m.a=m.cnum-2; System.out.println("Dentist "+m.a+"checks the patient "+t); Thread.sleep(1000); } //System.out.println("Dentist "+m.a+" sleeps "); } catch(Exception e){} } } public class Dentist { static int cnum=1,n,ch,n1,a,nu=1; public static void main(String[] args) { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Patient e=new Patient(); pat c=new pat(); int j; System.out.println("Enter no of Dentist : "); ch=Integer.parseInt(br.readLine()); System.out.println("Enter no of Patients : "); n=Integer.parseInt(br.readLine()); e.start();

if(ch<=n) { //n1=n-ch; //n=n-n1; while(cnum<=n) { int t=c.disp(cnum++); a=cnum-2; System.out.println("Dentist"+a+" checks " +" Patient" + t); Thread.sleep(1000); } } else { while(cnum<=n) { int t=c.disp(cnum++); a=cnum-2; System.out.println("Dentist"+a+" checks " +" Patient " + t); Thread.sleep(1000); } } while(nu<=ch) { System.out.println("Dentist"+nu+" sleeps "); nu++; } } catch(Exception e){} } }

OUTPUT: C:\Program Files\Java\jdk1.6.0_18\bin>javac Dentist.java C:\Program Files\Java\jdk1.6.0_18\bin>java Dentist Enter no of Dentist : 3 Enter no of Patients : 4 Dentist1 checks Patient1 Dentist 1checks the patient 2 Dentist2 checks Patient3 Dentist 2checks the patient 3 Dentist3 checks Patient4 Dentist1 sleeps Dentist2 sleeps Dentist3 sleeps C:\Program Files\Java\jdk1.6.0_18\bin>

You might also like