Advertisement
Guest User

StudentManagement

a guest
Sep 11th, 2017
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. package studentmanagement;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5. import java.lang.String;
  6.  
  7. public class StudentManagement {
  8. public static void main(String[] args) {
  9. // TODO code application logic here
  10. Student sv = new Student();
  11. sv.setName("Minh");
  12. sv.setID("123456");
  13. sv.setGroup("K61T");
  14. sv.setEmail("xxx@gmail.com");
  15. System.out.println("Name : "+ sv.getName());
  16. //sv.getInfo();
  17. System.out.println("Thong tin sinh vien : " + sv.getInfo());
  18.  
  19. Student s1 = new Student();
  20. Student s2 = new Student();
  21. Student s3 = new Student();
  22.  
  23. s1.setGroup("K59CLC");
  24. s2.setGroup("K59CLC");
  25. s3.setGroup("K59B");
  26.  
  27. if(sameGroup(s1, s2) == true){
  28. System.out.println("True");
  29. }
  30. else System.out.println("False");
  31.  
  32. if(sameGroup(s1, s3) == true){
  33. System.out.println("True");
  34. }
  35. else System.out.println("False");
  36.  
  37. Student s = new Student("Soi", "1", "x@mail.com");
  38.  
  39. System.out.println("Name :" + s.getName());
  40. System.out.println("ID : " + s.getID());
  41. System.out.println("Email : " + s.getEmail());
  42. System.out.println("Group : " + s.getGroup());
  43.  
  44. // Student[] svlist = new Student[100];
  45. //
  46. // svlist[0].setName("Anh");
  47. // svlist[0].setID("123");
  48. // svlist[1].setName("Binh");
  49. // svlist[1].setID("1111");
  50. //
  51. // for(Student index : svlist){
  52. // System.out.println("Name : " + index.getName());
  53. // System.out.println("ID : " +index.getID());
  54. // }
  55.  
  56. ArrayList<Student> listStudent = new ArrayList<Student>();
  57. Student svlist1 = new Student();
  58. svlist1.setName("Anh");
  59. svlist1.setID("123");
  60. svlist1.setGroup("K61T");
  61. svlist1.setEmail("qqq@gmail.com");
  62.  
  63. Student svlist2 = new Student();
  64. svlist2.setName("Binh");
  65. svlist2.setID("567");
  66. svlist2.setGroup("K61T");
  67. svlist2.setEmail("ppp@gmail.com");
  68.  
  69. listStudent.add(0,svlist1);
  70. listStudent.add(1,svlist2);
  71.  
  72. for(Student index : listStudent){
  73. System.out.println("Name " + index.getName());
  74. System.out.println("ID : " + index.getID());
  75. System.out.println("Group : " + index.getGroup());
  76. System.out.println("Email : " + index.getEmail());
  77. }
  78.  
  79. studentByGroup(listStudent);
  80.  
  81. removeStudent(listStudent);
  82. }
  83.  
  84. public static boolean sameGroup(Student s1, Student s2){
  85. boolean isSameGroup = false;
  86. if(s1.getGroup() == s2.getGroup()){
  87. isSameGroup = true;
  88. }
  89. return isSameGroup;
  90. }
  91.  
  92. public static void studentByGroup(ArrayList<Student> arrStudent){
  93. Scanner input = new Scanner(System.in);
  94. boolean isSameGroup = false;
  95. String group = new String();
  96.  
  97. System.out.println("Enter the group : ");
  98. group = input.next();
  99.  
  100. System.out.println("List of student in the group " + group + " : ");
  101. for(Student index : arrStudent)
  102. {
  103. if(index.getGroup().equals(group))
  104. {
  105. System.out.println(index.getName());
  106. }
  107. }
  108. }
  109.  
  110. public static void removeStudent(ArrayList<Student> arrStudent){
  111. Scanner input = new Scanner(System.in);
  112. String inputID = new String();
  113.  
  114. System.out.println("Enter the student's id : ");
  115. inputID = input.next();
  116.  
  117. for(Student indexStudent : arrStudent){
  118. if(indexStudent.getID().equals(inputID)){
  119. arrStudent.remove(arrStudent.indexOf(indexStudent));
  120. }
  121. }
  122.  
  123. }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement