From 2ae972a7bcdb63154a9bce5efe5456243f15a5b8 Mon Sep 17 00:00:00 2001 From: Luisa Fuentes Date: Wed, 14 Feb 2024 20:23:51 -0500 Subject: [PATCH] =?UTF-8?q?Arregl=C3=A9=20detalles=20finales=20de=20prints?= =?UTF-8?q?.=20Implement=C3=A9=20la=20b=C3=BAsqueda=20por=20ids=20para=20l?= =?UTF-8?q?a=20=C3=BAltima=20opci=C3=B3n=20y=20los=20Students=20repetidos?= =?UTF-8?q?=20ya=20no=20se=20agregan=20a=20una=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FinalExcercise/src/Models/Course.java | 2 +- .../EducationalCommunity/Professor.java | 2 +- .../Models/EducationalCommunity/Student.java | 31 ++++++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/FinalExcercise/src/Models/Course.java b/FinalExcercise/src/Models/Course.java index f48a23f..aef59a4 100644 --- a/FinalExcercise/src/Models/Course.java +++ b/FinalExcercise/src/Models/Course.java @@ -245,7 +245,7 @@ public static void listCoursesFromStudent(University university, Student student List courses = university.getCourses(); int id = student.getId(); String name_student = student.getName(); - System.out.println("Classes in which "+name_student+" is included" ); + System.out.println("Classes in which "+name_student+" is included: " ); for (Course course : courses) { diff --git a/FinalExcercise/src/Models/EducationalCommunity/Professor.java b/FinalExcercise/src/Models/EducationalCommunity/Professor.java index eb7f85d..03f68f3 100644 --- a/FinalExcercise/src/Models/EducationalCommunity/Professor.java +++ b/FinalExcercise/src/Models/EducationalCommunity/Professor.java @@ -55,7 +55,7 @@ public int getExperienceYears() { public static List createProfessors() { List professors = new ArrayList<>(); - Professor professor1 = new Professor("Francisco PĂ©rez",BASE_SALARY,PART_TIME,25,0); + Professor professor1 = new Professor("Francisco Castillo",BASE_SALARY,PART_TIME,25,0); Professor professor2 = new Professor("Marina Ladino",BASE_SALARY,FULL_TIME,45,5); professors.add(professor1); diff --git a/FinalExcercise/src/Models/EducationalCommunity/Student.java b/FinalExcercise/src/Models/EducationalCommunity/Student.java index 778a6a3..fa6d28e 100644 --- a/FinalExcercise/src/Models/EducationalCommunity/Student.java +++ b/FinalExcercise/src/Models/EducationalCommunity/Student.java @@ -112,7 +112,7 @@ public static List askForExistingStudents(University university, String for (Student student: students){ int id_student = student.getId(); for (String id: ids_entered) { - if (id_student == Integer.parseInt(id)) { + if (id_student == Integer.parseInt(id) && !students_chosen.contains(student)) { students_chosen.add(student); } } @@ -141,24 +141,31 @@ public static Object askForInfo(Object university, Scanner scan){ while (!student_entered) { - System.out.println("Enter the name of the student:"); + System.out.println("Enter the bullet number of the student for whom you want to review the enrolled courses: "); scan = new Scanner(System.in); - String entered_student_name = scan.nextLine().trim(); + int entered_student_id ; + List students= ((University) university).getStudents(); - if (entered_student_name.isEmpty()) { - System.out.println("Student name cannot be empty"); - continue; - } + try { + entered_student_id = scan.nextInt(); + + if (entered_student_id <= 0) { + System.out.println("Student id must be greater than zero"); + continue; + } + if(entered_student_id>students.size()){ + System.out.println("Student not found"); + continue; + } - if (entered_student_name.matches("\\d+")) { - System.out.println("Student name cannot consist of only numbers"); + } catch (InputMismatchException e) { + System.out.println("Please enter an integer"); continue; } - List students= ((University) university).getStudents(); for (Student student_registered: students) { - String name_student = student_registered.getName(); - if (name_student.equalsIgnoreCase(entered_student_name)) { + int id_student = student_registered.getId(); + if (id_student==entered_student_id) { student=student_registered; student_entered = true; }