-
Notifications
You must be signed in to change notification settings - Fork 12
Task 3 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Task 3 #18
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package task_3; | ||
|
|
||
| public class EmptyCoursesException extends Exception{ | ||
| public EmptyCoursesException(String message) { | ||
| super(message); | ||
| } | ||
| } | ||
| 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; | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
| 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) { | ||
|
||
| throw new IllegalArgumentException("Оценка должна быть от 1 до 5"); | ||
|
||
| } | ||
| this.gradeValue = gradeValue; | ||
| } | ||
| } | ||
| 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<>(); | ||
|
||
| 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); | ||
|
||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| 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(); | ||
|
||
| } | ||
| //simpsonsGradeList.add(new SimpsonsGrade(course, character, gradeValue)); | ||
|
||
| } | ||
|
|
||
| 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(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RuntimeException