1
1
package Models .EducationalCommunity ;
2
2
import Models .University ;
3
3
import Utils .ProperNounsManager ;
4
+ import Utils .Questioner ;
5
+
4
6
import java .util .ArrayList ;
5
7
import java .util .InputMismatchException ;
6
8
import java .util .List ;
7
9
import java .util .Scanner ;
8
10
9
- public class Student extends ProperNounsManager {
11
+ public class Student extends ProperNounsManager implements Questioner {
10
12
private static int lastId = 0 ;
11
13
int id ;
12
14
int age ;
@@ -99,7 +101,7 @@ public static Student askForStudentInfo(Scanner scan) {
99
101
public static List <Student > askForExistingStudents (University university , String entered_course_name , Scanner scan ){
100
102
List <Student > students = printStudents (university );
101
103
102
- System .out .println ("Enter the bullet number of the student(s) you want to add to the " + entered_course_name + " class followed by comas \n " +
104
+ System .out .println ("Enter the bullet number of the student(s) you want to add to the " + entered_course_name + " class followed by commas \n " +
103
105
"e.g: 1,2,5,4" );
104
106
scan = new Scanner (System .in );
105
107
String entered_ids = scan .nextLine ().trim ();
@@ -117,52 +119,53 @@ public static List<Student> askForExistingStudents(University university, String
117
119
}
118
120
return students_chosen ;
119
121
}
120
-
121
- public static Student askForStudentName (University university , Scanner scan ){
122
- printStudents (university );
123
122
123
+ public static List <Student > printStudents (University university ) {
124
+ System .out .println ("Here is a list of the existing students at the university:" );
125
+ List <Student > students = university .getStudents ();
126
+ for (Student student : students ) {
127
+ String name_student = student .getName ();
128
+ int id_student = student .getId ();
129
+ System .out .println (id_student + ". " + name_student );
130
+ }
131
+ return students ;
132
+ }
133
+
134
+ public static Object askForInfo (Object university , Scanner scan ){
124
135
Student student = null ;
125
- boolean student_entered = false ;
126
136
127
- while (!student_entered ) {
137
+ if (university instanceof University ){
138
+ printStudents ((University ) university );
128
139
129
- System .out .println ("Enter the name of the student:" );
130
- scan = new Scanner (System .in );
131
- String entered_student_name = scan .nextLine ().trim ();
140
+ boolean student_entered = false ;
132
141
133
- if (entered_student_name .isEmpty ()) {
134
- System .out .println ("Student name cannot be empty" );
135
- continue ;
136
- }
142
+ while (!student_entered ) {
137
143
138
- if (entered_student_name .matches ("\\ d+" )) {
139
- System .out .println ("Student name cannot consist of only numbers" );
140
- continue ;
141
- }
142
-
143
- List <Student > students = university .getStudents ();
144
- for (Student student_registered : students ) {
145
- String name_student = student_registered .getName ();
146
- if (name_student .equalsIgnoreCase (entered_student_name )) {
147
- student =student_registered ;
148
- student_entered = true ;
144
+ System .out .println ("Enter the name of the student:" );
145
+ scan = new Scanner (System .in );
146
+ String entered_student_name = scan .nextLine ().trim ();
147
+
148
+ if (entered_student_name .isEmpty ()) {
149
+ System .out .println ("Student name cannot be empty" );
150
+ continue ;
149
151
}
150
- }
151
-
152
- }
153
- return student ;
154
152
153
+ if (entered_student_name .matches ("\\ d+" )) {
154
+ System .out .println ("Student name cannot consist of only numbers" );
155
+ continue ;
156
+ }
155
157
156
- }
158
+ List <Student > students = ((University ) university ).getStudents ();
159
+ for (Student student_registered : students ) {
160
+ String name_student = student_registered .getName ();
161
+ if (name_student .equalsIgnoreCase (entered_student_name )) {
162
+ student =student_registered ;
163
+ student_entered = true ;
164
+ }
165
+ }
157
166
158
- public static List <Student > printStudents (University university ) {
159
- System .out .println ("Here is a list of the existing students at the university:" );
160
- List <Student > students = university .getStudents ();
161
- for (Student student : students ) {
162
- String name_student = student .getName ();
163
- int id_student = student .getId ();
164
- System .out .println (id_student + ". " + name_student );
167
+ }
165
168
}
166
- return students ;
169
+ return student ;
167
170
}
168
171
}
0 commit comments