Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/task_3/EmptyCoursesException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package task_3;

public class EmptyCoursesException extends Exception{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuntimeException

public EmptyCoursesException(String message) {
super(message);
}
}
62 changes: 62 additions & 0 deletions src/main/java/task_3/SimpsonsCharacter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package task_3;


import java.util.List;
public class SimpsonsCharacter {
private String name;
private int age;
private int characterId;
private List<SimpsonsCourse> enrolledCourses;
private List<SimpsonsGrade> grades;

public SimpsonsCharacter(String name, int age, int characterId, List<SimpsonsCourse> enrolledCourses, List<SimpsonsGrade> grades) {
setName(name);
setAge(age);
setCharacterId(characterId);
setEnrolledCourses(enrolledCourses);
setGrades(grades);
}

public SimpsonsCharacter() {
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public int getCharacterId() {
return characterId;
}

public void setCharacterId(int characterId) {
this.characterId = characterId;
}

public List<SimpsonsCourse> getEnrolledCourses() {
return enrolledCourses;
}

public void setEnrolledCourses(List<SimpsonsCourse> enrolledCourses) {
this.enrolledCourses = enrolledCourses;
}

public List<SimpsonsGrade> getGrades() {
return grades;
}

public void setGrades(List<SimpsonsGrade> grades) {
this.grades = grades;
}
}
29 changes: 29 additions & 0 deletions src/main/java/task_3/SimpsonsCourse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package task_3;
public class SimpsonsCourse {
private String courseName;
private int courseId;

public SimpsonsCourse() {
}

public SimpsonsCourse(String courseName, int courseId) {
setCourseName(courseName);
setCourseId(courseId);
}

public String getCourseName() {
return courseName;
}

public void setCourseName(String courseName) {
this.courseName = courseName;
}

public int getCourseId() {
return courseId;
}

public void setCourseId(int courseId) {
this.courseId = courseId;
}
}
43 changes: 43 additions & 0 deletions src/main/java/task_3/SimpsonsGrade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package task_3;

public class SimpsonsGrade {
private SimpsonsCourse course;
private SimpsonsCharacter character;
private int gradeValue;

public SimpsonsGrade() {
}

public SimpsonsGrade(SimpsonsCourse course, SimpsonsCharacter character, int gradeValue) {
setCourse(course);
setCharacter(character);
setGradeValue(gradeValue);
}

public SimpsonsCourse getCourse() {
return course;
}

public void setCourse(SimpsonsCourse course) {
this.course = course;
}

public SimpsonsCharacter getCharacter() {
return character;
}

public void setCharacter(SimpsonsCharacter character) {
this.character = character;
}

public int getGradeValue() {
return gradeValue;
}

public void setGradeValue(int gradeValue) {
if (gradeValue<=0 || gradeValue>5) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вынести числа в константы

throw new IllegalArgumentException("Оценка должна быть от 1 до 5");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А какая по факту?

}
this.gradeValue = gradeValue;
}
}
66 changes: 66 additions & 0 deletions src/main/java/task_3/SimpsonsSchool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package task_3;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class SimpsonsSchool {
// private List<SimpsonsGrade> simpsonsGradeList = new ArrayList<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Удалить

private List<SimpsonsCharacter> characterList = new ArrayList<>();
private List<SimpsonsCourse> courseList = new ArrayList<>();

public static void main(String[] args) {
SimpsonsSchool school = new SimpsonsSchool();
school.characterList.add(new SimpsonsCharacter("Ivan", 25, 1, new ArrayList<>(), new ArrayList<>()));
school.characterList.add(new SimpsonsCharacter("Petr", 24, 1, new ArrayList<>(), new ArrayList<>()));
school.characterList.add(new SimpsonsCharacter("Alexandr", 26, 1, new ArrayList<>(), new ArrayList<>()));
school.courseList.add(new SimpsonsCourse("Math", 1));
school.courseList.add(new SimpsonsCourse("Science", 2));
school.courseList.add(new SimpsonsCourse("Music", 3));
school.courseList.add(new SimpsonsCourse("History", 4));
for (SimpsonsCharacter character : school.characterList) {
school.enrollCharacter(character, school.courseList);
}

school.addGrade(school.characterList.get(1), school.courseList.get(0), 4);
school.addGrade(school.characterList.get(1), school.courseList.get(1), 3);
school.addGrade(school.characterList.get(1), school.courseList.get(2), 6);
school.addGrade(school.characterList.get(1), school.courseList.get(3), 1);
try {
school.getCharacterTranscript(school.characterList.get(1));
} catch (EmptyCoursesException e) {
throw new RuntimeException(e);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Залогировать, как минимум

}


}

public void enrollCharacter(SimpsonsCharacter character, List<SimpsonsCourse> courses) {
character.setEnrolledCourses(courses);
}

public void addGrade(SimpsonsCharacter character, SimpsonsCourse course, int gradeValue) {
try{
character.getGrades().add(new SimpsonsGrade(course, character, gradeValue));
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
e.printStackTrace();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно оставить только логирование всего стектрейса

}
//simpsonsGradeList.add(new SimpsonsGrade(course, character, gradeValue));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Удалить

}

public void getCharacterTranscript(SimpsonsCharacter character) throws EmptyCoursesException {
if (character.getEnrolledCourses().isEmpty()) {
throw new EmptyCoursesException("Список курсов у " + character.getName() + " пуст");
}
System.out.println(character.getName() + " записан на предметы:");
for (SimpsonsGrade simpsonsGrade : character.getGrades()) {
if (simpsonsGrade.getCharacter().equals(character)) {
System.out.print(simpsonsGrade.getCourse().getCourseName() + " - ");
System.out.print("Оценка - " + simpsonsGrade.getGradeValue() + ";");
System.out.println();
}
}

}
}