CymsSoul

Untitled

Dec 21st, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args)
  8. {
  9. Scanner reader = new Scanner(System.in);
  10. ArrayList<Student> list = new ArrayList<Student>();
  11.  
  12. while(true)
  13. {
  14. System.out.print("name: ");
  15. String studentName = reader.nextLine();
  16. if(studentName.isEmpty())
  17. {
  18. break;
  19. }
  20. System.out.print("studentnumber: ");
  21. String studentNumber = reader.nextLine();
  22. list.add(new Student(studentName,studentNumber));
  23.  
  24. }
  25.  
  26.  
  27. //list = gatherStudentData(list);
  28. System.out.println("");
  29. for(Student student : list)
  30. {
  31. System.out.println(student);
  32. }
  33.  
  34.  
  35. System.out.print("Give search term: ");
  36. String searchTerm = reader.nextLine();
  37. System.out.println("Result:");
  38.  
  39. for(Student student : list)
  40. {
  41. if(student.getName().contains(searchTerm))
  42. System.out.println(student);
  43. }
  44. }
  45.  
  46.  
  47. /*
  48. static private ArrayList<Student> gatherStudentData(ArrayList<Student> list)
  49. {
  50. Scanner reader = new Scanner(System.in);
  51. while(true)
  52. {
  53. System.out.print("name: ");
  54. String studentName = reader.nextLine();
  55. if(studentName.isEmpty())
  56. {
  57. break;
  58. }
  59. System.out.print("studentnumber: ");
  60. String studentNumber = reader.nextLine();
  61. list.add(new Student(studentName,studentNumber));
  62.  
  63. }
  64. return list;
  65. }
  66. */
  67. }
Advertisement
Add Comment
Please, Sign In to add comment