Skip to content

Commit

Permalink
Arreglé detalles finales de prints. Implementé la búsqueda por ids pa…
Browse files Browse the repository at this point in the history
…ra la última opción y los Students repetidos ya no se agregan a una class
  • Loading branch information
LuisaFuentesL committed Feb 15, 2024
1 parent 3469842 commit 2ae972a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion FinalExcercise/src/Models/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static void listCoursesFromStudent(University university, Student student
List<Course> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public int getExperienceYears() {
public static List<Professor> createProfessors() {
List<Professor> 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);
Expand Down
31 changes: 19 additions & 12 deletions FinalExcercise/src/Models/EducationalCommunity/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static List<Student> 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);
}
}
Expand Down Expand Up @@ -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<Student> 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<Student> 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;
}
Expand Down

0 comments on commit 2ae972a

Please sign in to comment.