Skip to content

Commit 3469842

Browse files
Merge pull request #2 from LuisaFuentesL/PF2-(Add)DiagramUML
Implementación Interface y diagrama UML
2 parents 3621974 + 2bcdc5b commit 3469842

File tree

5 files changed

+82
-64
lines changed

5 files changed

+82
-64
lines changed
Loading

FinalExcercise/src/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void main(String[] args) {
3434
case 2:
3535
System.out.println("Classes names: " );
3636
List<Course> courses = Course.printCourses(university, scan);
37-
Course.subMenu(courses, university, scan);
37+
Course.subMenu(courses, scan);
3838
break;
3939

4040
case 3:
@@ -47,7 +47,7 @@ public static void main(String[] args) {
4747
break;
4848

4949
case 5:
50-
Student student_required = Student.askForStudentName(university, scan);
50+
Student student_required = (Student) Student.askForInfo(university, scan);
5151
Course.listCoursesFromStudent(university, student_required);
5252
break;
5353

FinalExcercise/src/Models/Course.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import Models.EducationalCommunity.Professor;
44
import Models.EducationalCommunity.Student;
55
import Utils.ProperNounsManager;
6+
import Utils.Questioner;
67

78
import java.util.ArrayList;
89
import java.util.List;
910
import java.util.Scanner;
1011

11-
public class Course extends ProperNounsManager {
12+
public class Course extends ProperNounsManager implements Questioner {
1213
String classroom;
1314
List<Student> students;
1415
Professor professor;
@@ -102,7 +103,7 @@ public static List<Course> printCourses(University university, Scanner scan){
102103

103104
}
104105

105-
public static void subMenu(List<Course> courses, University university, Scanner scan){
106+
public static void subMenu(List<Course> courses, Scanner scan){
106107

107108
boolean course_found = false;
108109
while (!course_found) {
@@ -220,7 +221,7 @@ public static void askForNewCourse(University university, Scanner scan){
220221
}
221222
}
222223

223-
String classroom = askClassroom(entered_course_name,scan);
224+
String classroom = (String) askForInfo(entered_course_name, scan);
224225
Professor professor = Professor.askForProfessor(university, entered_course_name,scan);
225226
List<Student>students = Student.askForExistingStudents(university, entered_course_name, scan);
226227

@@ -239,27 +240,6 @@ public static void askForNewCourse(University university, Scanner scan){
239240
}
240241
}
241242

242-
public static String askClassroom(String entered_course_name, Scanner scan) {
243-
244-
boolean classroom_entered = false;
245-
246-
String entered_classroom = null;
247-
248-
while (!classroom_entered) {
249-
250-
System.out.println("Enter the name of the classroom you want to assign to the " + entered_course_name + " class:");
251-
scan = new Scanner(System.in);
252-
entered_classroom = scan.nextLine().trim();
253-
254-
if (entered_classroom.isEmpty()) {
255-
System.out.println("Classroom name cannot be empty");
256-
continue;
257-
} else {
258-
classroom_entered = true;
259-
}
260-
}
261-
return entered_classroom;
262-
}
263243

264244
public static void listCoursesFromStudent(University university, Student student){
265245
List<Course> courses = university.getCourses();
@@ -295,4 +275,30 @@ public static void printInfo(Object course) {
295275
}
296276
}
297277
}
278+
279+
280+
public static Object askForInfo(Object entered_course_name, Scanner scan) {
281+
String entered_classroom = null;
282+
283+
if(entered_course_name instanceof String){
284+
boolean classroom_entered = false;
285+
286+
287+
while (!classroom_entered) {
288+
289+
System.out.println("Enter the name of the classroom you want to assign to the " + entered_course_name + " class:");
290+
scan = new Scanner(System.in);
291+
entered_classroom = scan.nextLine().trim();
292+
293+
if (entered_classroom.isEmpty()) {
294+
System.out.println("Classroom name cannot be empty");
295+
continue;
296+
} else {
297+
classroom_entered = true;
298+
}
299+
}
300+
}
301+
return entered_classroom;
302+
303+
}
298304
}

FinalExcercise/src/Models/EducationalCommunity/Student.java

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package Models.EducationalCommunity;
22
import Models.University;
33
import Utils.ProperNounsManager;
4+
import Utils.Questioner;
5+
46
import java.util.ArrayList;
57
import java.util.InputMismatchException;
68
import java.util.List;
79
import java.util.Scanner;
810

9-
public class Student extends ProperNounsManager {
11+
public class Student extends ProperNounsManager implements Questioner {
1012
private static int lastId = 0;
1113
int id;
1214
int age;
@@ -99,7 +101,7 @@ public static Student askForStudentInfo(Scanner scan) {
99101
public static List<Student> askForExistingStudents(University university, String entered_course_name, Scanner scan){
100102
List<Student> students = printStudents(university);
101103

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" +
103105
"e.g: 1,2,5,4");
104106
scan = new Scanner(System.in);
105107
String entered_ids = scan.nextLine().trim();
@@ -117,52 +119,53 @@ public static List<Student> askForExistingStudents(University university, String
117119
}
118120
return students_chosen;
119121
}
120-
121-
public static Student askForStudentName(University university, Scanner scan){
122-
printStudents(university);
123122

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){
124135
Student student = null;
125-
boolean student_entered = false;
126136

127-
while (!student_entered) {
137+
if(university instanceof University){
138+
printStudents((University) university);
128139

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;
132141

133-
if (entered_student_name.isEmpty()) {
134-
System.out.println("Student name cannot be empty");
135-
continue;
136-
}
142+
while (!student_entered) {
137143

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;
149151
}
150-
}
151-
152-
}
153-
return student;
154152

153+
if (entered_student_name.matches("\\d+")) {
154+
System.out.println("Student name cannot consist of only numbers");
155+
continue;
156+
}
155157

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

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+
}
165168
}
166-
return students;
169+
return student;
167170
}
168171
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package Utils;
2+
3+
import java.util.Scanner;
4+
5+
public interface Questioner {
6+
public static Object askForInfo(Object obj, Scanner scan) {
7+
return null;
8+
}
9+
}

0 commit comments

Comments
 (0)