1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class a1 {
  5.  
  6. static LinkedList l1;
  7. private emp_struct input() throws IOException
  8. {
  9. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  10. emp_struct obj = new emp_struct();
  11. obj.emp_id = br.readLine();
  12. obj.name = br.readLine();
  13. obj.salary = Double.parseDouble(br.readLine());
  14. obj.dept = br.readLine();
  15. try{
  16. search(obj);
  17. }catch(Exception e){
  18. System.out.println(e);
  19. obj = input();
  20. }
  21. return obj;
  22.  
  23. }
  24.  
  25. boolean search(emp_struct obj)
  26. {
  27. int lastIndex = l1.lastIndexOf(l1);
  28. int begIndex = 0;
  29. for(begIndex =0;begIndex<lastIndex;begIndex++)
  30. {
  31. Object chkCase = l1.get(begIndex);
  32. String chk = chkCase.getEmpID();
  33. if(chk.equals(obj.emp_id));
  34. throw new DuplicateEntryException("Duplicate entry found");
  35.  
  36. }
  37. return true;
  38. }
  39. public static void main(String args[]) throws IOException
  40. {
  41. l1 = new LinkedList();
  42. }
  43. }
  44.  
  45. class DuplicateEntryException extends Exception {
  46. String detail;
  47. DuplicateEntryException(String a)
  48. {
  49. detail = a;
  50. }
  51.  
  52. public String toString()
  53. {
  54. return "User Defined Exception : "+detail;
  55. }
  56. }
  57.  
  58. class emp_struct {
  59. public String emp_id;
  60. public String name;
  61. public double salary;
  62. public String dept;
  63.  
  64. public String getEmpID()
  65. {
  66. return emp_id;
  67. }
  68.  
  69. public String toString()
  70. {
  71. return emp_id+"\t"+name+"\t"+salary+"\t"+dept;
  72. }
  73. }
  74.