Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. package studentdb;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class MainStudentdb
  9. {
  10. static List<Studentdb> st = new ArrayList<Studentdb>();
  11. public static void main(String[] args)
  12. {
  13. Scanner sc = new Scanner(System.in);
  14.  
  15. System.out.println("1.Admin login");
  16. System.out.println("2.User login");
  17. System.out.println("Exit");
  18. System.out.println("Enter your choice:");
  19. int choice = sc.nextInt();
  20. while(choice !=0)
  21. {
  22.  
  23. switch(choice)
  24. {
  25. case 1:
  26. System.out.println("Admin login");
  27. Adminlogin();
  28. showDetails();
  29. break;
  30. case 2:
  31. System.out.println("User login");
  32. userlogin();
  33. break;
  34. case 3:
  35. System.out.println("Exit");
  36. System.exit(0);
  37. break;
  38. }
  39. System.out.println("1.Admin login");
  40. System.out.println("2.User login");
  41. System.out.println("Exit");
  42. System.out.println("Enter your choice:");
  43. choice = sc.nextInt();
  44. }
  45. }
  46. public static void Adminlogin()
  47. {
  48. String username, password, name, regd_no, Branch, Semester;
  49. double CGPA;
  50. Scanner sc = new Scanner(System.in);
  51. System.out.println("------------------------------------");
  52. System.out.println("Enter username:");
  53. username = sc.nextLine();
  54. System.out.println("Enter password:");
  55. password = sc.nextLine();
  56. System.out.println("Enter name:");
  57. name = sc.nextLine();
  58. System.out.println("Enter regd_no:");
  59. regd_no = sc.nextLine();
  60. System.out.println("Enter branch:");
  61. Branch = sc.nextLine();
  62. System.out.println("Enter semester:");
  63. Semester = sc.nextLine();
  64. System.out.println("Enter CGPA:");
  65. CGPA = sc.nextDouble();
  66. System.out.println("------------------------------------");
  67. Studentdb db = new Studentdb();
  68. db.setUsername(username);
  69. db.setPassword(password);
  70. db.setName(name);
  71. db.setRegd_no(regd_no);
  72. db.setBranch(Branch);
  73. db.setSemester(Semester);
  74. db.setCGPA(CGPA);
  75. st.add(db);
  76. }
  77.  
  78. static void showDetails()
  79. {
  80.  
  81. Iterator<Studentdb> i = st.iterator();
  82. while(i.hasNext())
  83. {
  84. Studentdb p= i.next();
  85. System.out.println("-------------------------------");
  86. System.out.println(p.getUsername());
  87. System.out.println(p.getPassword());
  88. System.out.println(p.getName());
  89. System.out.println(p.getRegd_no());
  90. System.out.println(p.getBranch());
  91. System.out.println(p.getCGPA());
  92. System.out.println("-------------------------------");
  93. }
  94. }
  95. public static void userlogin()
  96. {
  97. String username, password, name, regd_no, Branch, Semester;
  98. double CGPA;
  99. Scanner sc = new Scanner(System.in);
  100. System.out.println("Enter username:");
  101. username = sc.nextLine();
  102. System.out.println("Enter password:");
  103. password = sc.nextLine();
  104. Iterator<Studentdb> i = st.iterator();
  105. boolean flag=false;
  106. while(i.hasNext())
  107. {
  108. Studentdb p= i.next();
  109. if(username.equals(p.getUsername()) && password.equals(p.getPassword()))
  110. {
  111. System.out.println("-------------------------------");
  112. System.out.println(p.getUsername());
  113. System.out.println(p.getPassword());
  114. System.out.println(p.getName());
  115. System.out.println(p.getRegd_no());
  116. System.out.println(p.getBranch());
  117. System.out.println(p.getCGPA());
  118. System.out.println("-------------------------------");
  119.  
  120. flag=true;
  121. }
  122.  
  123. }
  124. if(!flag){
  125.  
  126. System.out.println("Wrong username or password");
  127.  
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement