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