Skip to content

Commit 2ae972a

Browse files
committed
Arreglé detalles finales de prints. Implementé la búsqueda por ids para la última opción y los Students repetidos ya no se agregan a una class
1 parent 3469842 commit 2ae972a

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

FinalExcercise/src/Models/Course.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public static void listCoursesFromStudent(University university, Student student
245245
List<Course> courses = university.getCourses();
246246
int id = student.getId();
247247
String name_student = student.getName();
248-
System.out.println("Classes in which "+name_student+" is included" );
248+
System.out.println("Classes in which "+name_student+" is included: " );
249249

250250

251251
for (Course course : courses) {

FinalExcercise/src/Models/EducationalCommunity/Professor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public int getExperienceYears() {
5555
public static List<Professor> createProfessors() {
5656
List<Professor> professors = new ArrayList<>();
5757

58-
Professor professor1 = new Professor("Francisco Pérez",BASE_SALARY,PART_TIME,25,0);
58+
Professor professor1 = new Professor("Francisco Castillo",BASE_SALARY,PART_TIME,25,0);
5959
Professor professor2 = new Professor("Marina Ladino",BASE_SALARY,FULL_TIME,45,5);
6060

6161
professors.add(professor1);

FinalExcercise/src/Models/EducationalCommunity/Student.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static List<Student> askForExistingStudents(University university, String
112112
for (Student student: students){
113113
int id_student = student.getId();
114114
for (String id: ids_entered) {
115-
if (id_student == Integer.parseInt(id)) {
115+
if (id_student == Integer.parseInt(id) && !students_chosen.contains(student)) {
116116
students_chosen.add(student);
117117
}
118118
}
@@ -141,24 +141,31 @@ public static Object askForInfo(Object university, Scanner scan){
141141

142142
while (!student_entered) {
143143

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: ");
145145
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();
147148

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+
}
152160

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");
155163
continue;
156164
}
157165

158-
List<Student> students= ((University) university).getStudents();
159166
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) {
162169
student=student_registered;
163170
student_entered = true;
164171
}

0 commit comments

Comments
 (0)