Search This Blog

Friday 15 July 2022

6. NEP Java Program to define a class called employee with the name and date of appointment. Create ten employee objects as an array and sort them as per their date of appointment i.e., print them as per their seniority.

6. Program to define a class called employee with the name and date of appointment. Create ten employee objects as an array and sort them as per their date of appointment i.e., print them as per their seniority.

import java.io.*;

import java.util.*;

class employee

{

     String ename;

     Date doa;

     public employee(String ename,Date doa)

     {

          this.ename=ename;

          this.doa=doa;

     }

     public void display()

     {

System.out.println("Employee Name:"+ename+"  Date of Appointment:"+  doa.getDate()+"/" +doa.getMonth()+"/"+doa.getYear());

     }

}

 

class Program61

{

     public static void main(String as[]) throws IOException

     {

          employee eobj[]=new employee[10];

          eobj[0]=new employee("AAA",new Date(2022,05,18));

          eobj[1]=new employee("BBB",new Date(2021,07,20));

          eobj[2]=new employee("CCC",new Date(2018,05,15));

          eobj[3]=new employee("DDD",new Date(2019,02,11));

          eobj[4]=new employee("EEE",new Date(2010,03,12));

          eobj[5]=new employee("FFF",new Date(2008,04,15));

          eobj[6]=new employee("GGG",new Date(2005,06,18));

          eobj[7]=new employee("HHH",new Date(2022,05,21));

          eobj[8]=new employee("III",new Date(2004,05,20));

          eobj[9]=new employee("JJJ",new Date(2005,06,14));

                  

          System.out.println("List of Employees");

          for(int i=0;i<eobj.length;i++)

                   eobj[i].display();

          for(int i=0;i<eobj.length;i++)

          {

              for(int j=0;j<eobj.length;j++)

              {

                   if(!eobj[i].doa.after(eobj[j].doa))

                   {

                        employee t=eobj[i];

                        eobj[i]=eobj[j];

                        eobj[j]=t;

                   }

              }

          }

       System.out.println("List of Employees Seniority-wise");

          for(int i=0;i<eobj.length;i++)

          eobj[i].display();

     }

 

}

No comments :

Post a Comment

FREE Hit Counters