Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander committed Jun 12, 2021
2 parents e520765 + 3ebde33 commit 6b043bb
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/exceptions/EmptyEvaluationException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package exceptions;

@SuppressWarnings("serial")
public class EmptyEvaluationException extends Exception {

public EmptyEvaluationException() {
super("La evaluacion no tiene contenido");
}

}
26 changes: 26 additions & 0 deletions src/exceptions/ExistingCodeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package exceptions;

@SuppressWarnings("serial")
public class ExistingCodeException extends Exception {

private String code;

public ExistingCodeException(String code) {
super("El codigo " + code + "ya esta asociado a un estudiante existente.");
}

/**
* @return the code
*/
public String getCode() {
return code;
}

/**
* @param code the code to set
*/
public void setCode(String code) {
this.code = code;
}

}
67 changes: 59 additions & 8 deletions src/model/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.util.Collections;
import java.util.Comparator;

import exceptions.EmptyEvaluationException;
import exceptions.ExistingCodeException;

public class Course implements Serializable{

/**
Expand Down Expand Up @@ -141,12 +144,15 @@ public void setAverageGrades(ArrayList<Grade> averageGrades) {
this.averageGrades = averageGrades;
}

public boolean addStudent(String name, String lastName, String email, String code) throws IOException {
public boolean addStudent(String name, String lastName, String email, String code) throws IOException, ExistingCodeException {
boolean added = false;
Student newStudent = new Student(name, lastName, email, code);
if(!students.contains(newStudent)) {
added = students.add(newStudent);
}
if(searchStudent(code) != null) {
throw new ExistingCodeException(code);
}
return added;
}

Expand Down Expand Up @@ -209,15 +215,43 @@ public int compare(Student obj1, Student obj2) {
return key;
}

public void sortByLastName() {
for(int i = 1; i < students.size(); i++) {
int j = i;
Student st = students.get(i);
while(j >= 0 && (st.compareByLastName(students.get(j))) > 0) {
students.set(j+1, students.get(j));
j--;
}
students.set(j+1, st);
}
}

public void sortByFinalGrade() {
for(int i = 1; i < students.size(); i++) {
int j = i;
Student st = students.get(i);
while(j >= 0 && (st.compareByFinalGrade(students.get(j))) < 0) {
students.set(j+1, students.get(j));
j--;
}
students.set(j+1, st);
}
}

//MANAGEMENT EVALUATIONS

//Add Questionnaire

public boolean addQuestionnaire(String topic, int percentage, String content, LocalDate date, int attempts) {
public boolean addQuestionnaire(String topic, int percentage, String content, LocalDate date, int attempts) throws EmptyEvaluationException {
boolean added = false;
Activity newQuestionnaire = new Questionnaire(topic, percentage, content, date, attempts);
if(!activities.contains(newQuestionnaire)) {
added = activities.add(newQuestionnaire);
if(content.isEmpty()) {
throw new EmptyEvaluationException();
}else {
added = activities.add(newQuestionnaire);
}
}
return added;
}
Expand Down Expand Up @@ -263,11 +297,15 @@ public boolean deleteQuestionnaire(Questionnaire q) {

//Add WorkShop

public boolean addWorkshop(String topic, int percentage, String content, LocalDate date, String answers) {
public boolean addWorkshop(String topic, int percentage, String content, LocalDate date, String answers) throws EmptyEvaluationException {
boolean added = false;
Activity newWorkshop = new Workshop(topic, percentage, content, date, answers);
if(!activities.contains(newWorkshop)) {
added = activities.add(newWorkshop);
if(content.isEmpty()) {
throw new EmptyEvaluationException();
}else {
added = activities.add(newWorkshop);
}
}
return added;
}
Expand Down Expand Up @@ -313,11 +351,15 @@ public boolean deleteWorkshop (Workshop w) {

//Add Exams

public boolean addExam(String topic, int percentage, String content, int timeLimit) {
public boolean addExam(String topic, int percentage, String content, int timeLimit) throws EmptyEvaluationException {
boolean added = false;
Exam newExam = new Exam(topic, percentage, content, timeLimit);
if(!exams.contains(newExam)) {
added = exams.add(newExam);
if(content.isEmpty()) {
throw new EmptyEvaluationException();
}else {
added = exams.add(newExam);
}
}
return added;
}
Expand All @@ -334,6 +376,15 @@ public void updateExam(Exam e, String topic, int percentage, String content, int

//Delete Exam

public boolean deleteExam(Exam e) throws IOException {
boolean deleted = false;
if(exams.contains(e)) {
deleted = exams.remove(e);
}
return deleted;
}


//IMPORT STUDENTS

public void importStudents(String fileName, String separator) throws IOException {
Expand Down Expand Up @@ -442,7 +493,7 @@ public void exportQuestionnaires(String fileName, String separator) throws FileN

//IMPORT EXAMS

public void importExams(String fileName, String separator) throws IOException {
public void importExams(String fileName, String separator) throws IOException, EmptyEvaluationException {
BufferedReader br = new BufferedReader(new FileReader(fileName));
String line = br.readLine();
while (line!=null ) {
Expand Down
4 changes: 4 additions & 0 deletions src/model/Questionnaire.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

public class Questionnaire extends Activity {

/**
*
*/
private static final long serialVersionUID = 1L;
private int attempts;

public Questionnaire(String topic, int percentage, String content, LocalDate date, int attempts) {
Expand Down
16 changes: 15 additions & 1 deletion src/model/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,21 @@ public double getFinalAverageGrade() {
public void setFinalAverageGrade(double finalAverageGrade) {
this.finalAverageGrade = finalAverageGrade;
}


public int compareByLastName(Student s1) {
return getLastName().compareToIgnoreCase(s1.getLastName());
}

public int compareByFinalGrade(Student other) {
if(finalAverageGrade == other.getFinalAverageGrade()) {
return 0;
}else if(finalAverageGrade > other.getFinalAverageGrade()) {
return 1;
}else {
return -1;
}
}

/**
* @return the parent
*/
Expand Down
23 changes: 23 additions & 0 deletions src/model/Teacher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Teacher extends Member implements Serializable{

Expand Down Expand Up @@ -199,4 +201,25 @@ private Course searchCourse(String name, Course current) {
}
return courseSearched;
}

public Course binarySearchCourse(String courseName) {
Comparator<Course> name = new Comparator<Course>() {
@Override
public int compare(Course obj1, Course obj2) {
String n1 = obj1.getCourseName().toLowerCase();
String n2 = obj2.getCourseName().toLowerCase();

return n2.compareTo(n1);
}
};

Course key = new Course(courseName);
int index = Collections.binarySearch(getCourses(), key, name);
if (index < 0){
key = null;
}else {
key = getCourses().get(index);
}
return key;
}
}
4 changes: 4 additions & 0 deletions src/model/Workshop.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

public class Workshop extends Activity {

/**
*
*/
private static final long serialVersionUID = 1L;
private String answers;

public Workshop(String topic, int percentage, String content, LocalDate date, String answers) {
Expand Down
12 changes: 11 additions & 1 deletion src/ui/CoursesGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.IOException;
import java.util.Optional;

import exceptions.ExistingCodeException;

public class CoursesGUI {


Expand Down Expand Up @@ -165,7 +167,15 @@ void createNewStudent(ActionEvent event) {
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (ExistingCodeException e) {
// TODO Auto-generated catch block
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("ExistingCodeException");
alert.setHeaderText("No ha sido posible crear el nuevo estudiante");
alert.setContentText(e.getMessage() + "\n\nInténtelo de nuevo.");
alert.showAndWait();
e.printStackTrace();
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/ui/ExamsGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.IOException;
import java.util.Optional;

import exceptions.EmptyEvaluationException;

public class ExamsGUI {

private EvaluationSystem evaluationSystem;
Expand Down Expand Up @@ -166,7 +168,15 @@ void importExamsList(ActionEvent event) {
currentCourse.importExams(file.getAbsolutePath(), separator);
} catch (IOException e) {
e.printStackTrace();
}
} catch (EmptyEvaluationException e) {
// TODO Auto-generated catch block
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("EmptyEvaluationException");
alert.setHeaderText("No ha sido posible importar todos los examenes");
alert.setContentText("Hay examen(es) sin contenido. \n\nInténtelo de nuevo.");
alert.showAndWait();
e.printStackTrace();
}

}
}
Expand Down

0 comments on commit 6b043bb

Please sign in to comment.