Define a class named “Employee” with the following private fields: EmpID , EmpName , DeptID , Bloodgroup , Salary. Declare 2 public methods to get and set the private fields. Create an array of employee objects. Prompt the user for providing values. Show the details of each employee.

class Employee
{
 int empID,DeptID,Salary;
 String empName,BloodGroup;

   void setEmpDetails()
    {
     empID=Integer.parseInt(System.console().readLine("Enter the empID="));
     empName=System.console().readLine("Enter the empname=");
     DeptID=Integer.parseInt(System.console().readLine("Enter the DeptID="));
     BloodGroup=System.console().readLine("Enter the BloodGroup=");
     Salary=Integer.parseInt(System.console().readLine("Enter the Salary="));
    }

  void getEmpDetails()
   {
    System.out.println(" ");
    System.out.println(" ");
    System.out.println(" ");
    System.out.println("************Employee Details**************");
    System.out.println(" ");
    System.out.println(" ");
    System.out.println(" ");
    System.out.println("Employee Id            :"+empID);
    System.out.println("Employee Name          :"+empName);
    System.out.println("Department Id          :"+DeptID);
    System.out.println("Employee Blood group   :"+BloodGroup);
    System.out.println("Employee Salary        :"+Salary);
   }
}

class EmployeeTestDrive
  {
      public static void main(String[] args)
       {
         Employee e=new Employee();
         e.setEmpDetails();
         e.getEmpDetails();
       }
  }

4 comments:

  1. this is showing a lot of errors

    ReplyDelete
  2. no its not showing errors..its absolutely correct

    ReplyDelete
  3. how to use this with exceptions??

    ReplyDelete
  4. where is the array of object???

    ReplyDelete