linked list i assess
Thu Apr 18 2024 07:01:31 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
import java.util.*;
class Abhi implements Comparator<Employee>{
public int compare(Employee a, Employee b)
{
return a.fName.compareTo(b.fName);
}
}
public class Main {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
LinkedList<Employee> l=new LinkedList<>();
System.out.println("Enter The Number of Employees");
int n=sc.nextInt();
sc.nextLine();
for(int i=1;i<=n;i++)
{
System.out.println("Enter The "+i+" Employee Details:");
System.out.println("Enter the Firstname");
String s1=sc.nextLine();
System.out.println("Enter theLastname");
String s2=sc.nextLine();
System.out.println("Enter the Mobile");
String s3=sc.nextLine();
System.out.println("Enter the Email");
String s4=sc.nextLine();
System.out.println("Enter the Address");
String s5=sc.nextLine();
Employee e=new Employee(s1,s2,s3,s4,s5);
l.add(e);
}
Collections.sort(l,new Abhi()) ;
System.out.println("Employee List:");
System.out.format("%-15s %-15s %-15s %-30s %-15s\n","Firstname","Lastname","Mobile","Email","Address");
for(Employee e: l)
{
e.display();
}
}
}
public class Employee{
public String fName;
private String lName;
private String mNum;
private String eMail;
private String address;
public Employee(String fName,String lName,String mNum,String eMail,String address)
{
this.fName=fName;
this.lName=lName;
this.mNum=mNum;
this.eMail=eMail;
this.address=address;
}
public String getfName(){
return fName;
}
public void display()
{
System.out.format("%-15s %-15s %-15s %-30s %-15s\n",fName,lName,mNum,eMail,address);
}
}
content_copyCOPY
Comments