Diseño y Programación Orientada a Objetos Conferencia # 5: Caso de estudio integrador: Control docente Facultad Ing. Informática ISPJAE
Se desea automatizar el procesamiento de la información final de un curso de los estudiantes de un año, conociendo los datos de cada estudiante, los datos de cada asignatura y la nota de cada estudiante en cada asignatura.
De los estudiantes se conoce nombre, grupo, si es becado o no y el promedio final de los cursos anteriores. De cada asignatura se conoce, nombre, cantidad de horas presenciales y semestre en que se impartió.
Requerimientos funcionales. Total de horas presenciales del año. Modificar la nota de un estudiante en una asignatura dada. % de aprobados de una asignatura.
Promedio de un estudiante, solo si tiene todas las asignaturas aprobadas y actualizar su registro de promedios. % de becados suspensos en el curso. Cantidad de estudiantes que terminaron el 1er semestre con tres o más asignaturas suspensas.
¿Modelo de datos?
Estudiantes j Asignaturas i Nota en asignatura i del estudiante j
Diseños de clases
Variante 1 Controler IntMatrix mark Student Course String name 0..* 1 0..* Student String name String group boolean scholarship FloatArray average Course String name int hour int semester
Variante 2 Controller IntMatrix mark StudentCollection 1 1 1 1 StudentCollection CourseCollection 1 1 0..* 0..* Student Course
Variante 3 1 1 1 1 Controller 1 1 StudentCollection CourseCollection 1 Mark IntMatrix mark 1 1 1 1 Controller 1 1 StudentCollection CourseCollection 1 1 0..* 0..* Student Course
Implementación Variante 2
public class Student { private String name; private String group; private boolean scholarship; private FloatArray average; public Student(String name, String group, boolean scholarship) { this.name = name; this.group = group; this.scholarship = scholarship; average = new FloatArray(); } ...
public String getGroup(){return group;} public String getName() {return name;} public boolean getScholarship() {…} public void setGroup(String group) {…} public void setName(String name) {…} public void setScholarship(…) {…}
public float getAverageInYear(int if(year>0 && year<average.getCount()) return average.get(year-1); else return -1; } public void setAverageInYear(int year, float value) { average.set(year-1,value);
public boolean addAverage(float value) { if(average.getCount() < 5) { average.add(value); return true; } else return false;
public class Course { private String name; private int hour; private int semester; public Course(String name, int hour, int semester) { this.name = name; this.hour = hour; this.semester = semester; } … }
public class StudentCollection { private Student[] students; private int count; public static final int DEFAULT_CAPACITY = 10; private void ensureCapcity(int minCapacity){…} private boolean rangeIsValid (int index) { if(index >= 0 && index < count) return true; else return false; }
public StudentCollection() { this(DEFAULT_CAPACITY);} public StudentCollection(int capacity) { if (capacity > 0) students = new Student[capacity]; else students = new Student[DEFAULT_CAPACITY]; }
public int getCount() {return count;} public int find(String name) { int i=0; while (i < count && !students[i].getName(). equalsIgnoreCase(name)) i++; return i < count? i : -1; }
public boolean add(String name, String group, boolean scholarship) { boolean result = false; if (find(name) == -1){ if (count == students.length) ensureCapacity(1); students[count++] = new Student(name,group,scholarship); result = true; } return result; }
public float getAverage(String name, int year) { int pos = find(name); if (pos != -1) return students[pos].getAverageInYear(year); else return -1; } … }
public class CourseCollection { private Course[] courses; private int count; public static final int DEFAULT_CAPACITY = 10; …
public int totalHours(){ //Total de horas presenciales int sum= 0; for(int i= 0; i < count; i++) sum += courses[i].getHour(); return sum; } …}
public class Secretary { private CourseCollection courses; private StudentCollection students; private IntMatrix marks;
public Secretary () { courses= new CourseCollection(); students= new StudentCollection(); marks= new IntMatrix(courses.DEFAULT_CAPACITY, students.DEFAULT_CAPACITY); }
public Secretary (int capacityCourses, int capacityStudents) { … } public boolean addStudent(String name, String group,boolean scholarship) { boolean result = students.add(name,group,scholarship); if (result) marks.addColZero(); return result;}
public int getMark(String course, String student) { int row = courses.find(course); int col = students.find(student); if (row != -1 && col != -1) return marks.get(row, col); else return -1; }
public boolean setMark(String course, String student, int value) { int row = courses.find(course); int col = students.find(student); if (row != -1 && col != -1) { marks.set(row, col, value); return true; } else return false;
% de aprobados de una asignatura. public float percentApproved(String course) { int row = courses.find(course); if (row == -1) return -1; else { int countApproved= marks.countBiggerThan(row,0, row,marks.getColCount()-1,2); return (float)countApproved / marks.getColCount()* 100; } }
public int totalHours() { //Total de horas presenciales return courses.totalHours(); }
Conclusiones Consistencia en el enfoque OO Utilidad de clases generales Responsabilidades compartidas
Estudio Independiente Completar la implementación de los requerimientos funcionales especificados. Implementar la Variante 3.