2).Employee’s details are maintained by organization and that contains parameter namely name, designation, salary, department and experience. Create individual thread for each employee and display information of them at a regular interval. [Assume that there are four employees in the company].
===============================================
import java.io.*;
class Employee extends Thread{ String name,desig,salary,dept,exp; synchronized public void display() { synchronized(System.out) { System.out.println("Name : " + name); try{ Thread.sleep(1000); }catch(InterruptedException ex){} System.out.println("Designation : " + desig); try{ Thread.sleep(1000); }catch(InterruptedException ex){} System.out.println("salary : " + salary); try{ Thread.sleep(1000); }catch(InterruptedException ex){} System.out.println("Department : " + dept); try{ Thread.sleep(1000); }catch(InterruptedException ex){} System.out.println("Experience : " + exp); try{ Thread.sleep(1000); }catch(InterruptedException ex){} } } void getData() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Employee Name : "); name = br.readLine(); System.out.print("Employee Designation : "); desig = br.readLine(); System.out.print("Employee Salary : "); salary = br.readLine(); System.out.print("Employee Department : "); dept = br.readLine(); System.out.print("Employee Experience : "); exp = br.readLine();
} public void run() { display(); }}
class EmployeeMain{ public static void main(String Args[]) throws Exception { Employee e1 = new Employee(); Employee e2 = new Employee();
Employee e3 = new Employee(); Employee e4 = new Employee();
e1.getData(); e2.getData();e3.getData(); e4.getData();
e1.start(); e2.start(); e3.start();e4.start();
}}
No comments :
Post a Comment