@@ -112,7 +112,7 @@ public static List<Student> askForExistingStudents(University university, String
112
112
for (Student student : students ){
113
113
int id_student = student .getId ();
114
114
for (String id : ids_entered ) {
115
- if (id_student == Integer .parseInt (id )) {
115
+ if (id_student == Integer .parseInt (id ) && ! students_chosen . contains ( student ) ) {
116
116
students_chosen .add (student );
117
117
}
118
118
}
@@ -141,24 +141,31 @@ public static Object askForInfo(Object university, Scanner scan){
141
141
142
142
while (!student_entered ) {
143
143
144
- System .out .println ("Enter the name of the student: " );
144
+ System .out .println ("Enter the bullet number of the student for whom you want to review the enrolled courses: " );
145
145
scan = new Scanner (System .in );
146
- String entered_student_name = scan .nextLine ().trim ();
146
+ int entered_student_id ;
147
+ List <Student > students = ((University ) university ).getStudents ();
147
148
148
- if (entered_student_name .isEmpty ()) {
149
- System .out .println ("Student name cannot be empty" );
150
- continue ;
151
- }
149
+ try {
150
+ entered_student_id = scan .nextInt ();
151
+
152
+ if (entered_student_id <= 0 ) {
153
+ System .out .println ("Student id must be greater than zero" );
154
+ continue ;
155
+ }
156
+ if (entered_student_id >students .size ()){
157
+ System .out .println ("Student not found" );
158
+ continue ;
159
+ }
152
160
153
- if ( entered_student_name . matches ( " \\ d+" ) ) {
154
- System .out .println ("Student name cannot consist of only numbers " );
161
+ } catch ( InputMismatchException e ) {
162
+ System .out .println ("Please enter an integer " );
155
163
continue ;
156
164
}
157
165
158
- List <Student > students = ((University ) university ).getStudents ();
159
166
for (Student student_registered : students ) {
160
- String name_student = student_registered .getName ();
161
- if (name_student . equalsIgnoreCase ( entered_student_name ) ) {
167
+ int id_student = student_registered .getId ();
168
+ if (id_student == entered_student_id ) {
162
169
student =student_registered ;
163
170
student_entered = true ;
164
171
}
0 commit comments