diff --git a/src/main/java/lessons/lesson05/educationCentre/Course.java b/src/main/java/lessons/lesson05/educationCentre/Course.java new file mode 100644 index 0000000..ea0e41d --- /dev/null +++ b/src/main/java/lessons/lesson05/educationCentre/Course.java @@ -0,0 +1,59 @@ +package lessons.lesson05.educationCentre; + +import java.util.ArrayList; + +public class Course { + private String name; + private String teacher; + private ArrayList student = new ArrayList<>(); + private ArrayList attendanceJournal = new ArrayList<>(); + + public String getName() { + return name; + } + + public String getTeacher() { + return teacher; + } + + public void setTeacher(String teacher) { + this.teacher = teacher; + } + + public Course(String name, String teacher) { + this.name = name; + this.teacher = teacher; + } + + public void addStudent(Student s) { + for (Student student1 : student) { + if (student1.getEmail().equals(s.getEmail())) { + System.out.println("This student is already studying!"); + return; + } + } + student.add(s); + } + + public void recordAttendance(Student s, boolean present) { + if (s.getEnrolledCourse().equals(name) && present) { + attendanceJournal.add(s); + System.out.println(s.getName() + " has attended!"); + } else { + System.out.println(s.getName() + " was absent."); + } + } + + public void recordGrade(Student s, double grade) { + s.setGrades(grade); + System.out.println("Teacher set grade " + grade + " for " + s.getName()); + } + + public void showStudents() { + System.out.println("The list of attendants of " + name + " course:"); + for (Student student1 : student) { + student1.studentInfo(); + } + System.out.println(); + } +} diff --git a/src/main/java/lessons/lesson05/educationCentre/MainEducation.java b/src/main/java/lessons/lesson05/educationCentre/MainEducation.java new file mode 100644 index 0000000..0ab8847 --- /dev/null +++ b/src/main/java/lessons/lesson05/educationCentre/MainEducation.java @@ -0,0 +1,29 @@ +package lessons.lesson05.educationCentre; + +public class MainEducation { + public static void main(String[] args) { + Teacher teacher = new Teacher("Yevgeny", 2309, "yevgeny@uzum.com"); + Course java = new Course("Java Junior", "none"); + Student student = new Student("Feruz", 25091, "feruz@uzum.com", "", 0); + Student student1 = new Student("Matvey", 25092, "matvey@uzum.com", java.getName(), 0); + + student.enroll(java); + java.addStudent(student1); + java.showStudents(); + System.out.println(); + + student.attendCourse(java); + java.recordAttendance(student, true); + System.out.println(); + + teacher.assignCourse(java); + teacher.gradeStudent(student, java, 100.0); + java.showStudents(); + + Student student2 = new Student("Feruz", 25091, "feruz@uzum.com", "", 0); + java.addStudent(student2); + java.showStudents(); + + + } +} diff --git a/src/main/java/lessons/lesson05/educationCentre/Person.java b/src/main/java/lessons/lesson05/educationCentre/Person.java new file mode 100644 index 0000000..ec72bf8 --- /dev/null +++ b/src/main/java/lessons/lesson05/educationCentre/Person.java @@ -0,0 +1,34 @@ +package lessons.lesson05.educationCentre; + +public abstract class Person { + private String name; + private int id; + private String email; + + public Person(String name, int id, String email) { + this.name = name; + this.id = id; + this.email = email; + } + + public String getInfo() { + return "Name: " + name + "\nID: " + id + "\nEmail: " + email; + } + + public void introduce() { + System.out.println("Hello. My name is " + name); + } + + public String getEmail() { + return email; + } + + public String getName() { + return name; + } + + public int getId() { + return id; + } +} + diff --git a/src/main/java/lessons/lesson05/educationCentre/Student.java b/src/main/java/lessons/lesson05/educationCentre/Student.java new file mode 100644 index 0000000..7fdb9c5 --- /dev/null +++ b/src/main/java/lessons/lesson05/educationCentre/Student.java @@ -0,0 +1,39 @@ +package lessons.lesson05.educationCentre; + +public class Student extends Person { + private String enrolledCourse; + private double grades; + + public String getEnrolledCourse() { + return enrolledCourse; + } + + public double getGrades() { + return grades; + } + + public void setGrades(double grades) { + this.grades = grades; + } + + public Student(String name, int id, String email, String enrolledCourse, double grades) { + super(name, id, email); + this.enrolledCourse = enrolledCourse; + this.grades = grades; + } + + public void enroll(Course course) { + enrolledCourse = course.getName(); + System.out.println(this.getName() + " enrolled " + enrolledCourse); + course.addStudent(this); + } + + public void attendCourse(Course course) { + System.out.println("I attended!"); + course.recordAttendance(this, true); + } + + public void studentInfo() { + System.out.println(getInfo()); + } +} diff --git a/src/main/java/lessons/lesson05/educationCentre/Teacher.java b/src/main/java/lessons/lesson05/educationCentre/Teacher.java new file mode 100644 index 0000000..2cb95ca --- /dev/null +++ b/src/main/java/lessons/lesson05/educationCentre/Teacher.java @@ -0,0 +1,28 @@ +package lessons.lesson05.educationCentre; + +public class Teacher extends Person { + private String specialization; + + public Teacher(String name, int id, String email) { + super(name, id, email); + } + + public void assignCourse(Course course) { + specialization = course.getName(); + System.out.println(getName() + " is teacher of " + specialization); + course.setTeacher(this.getName()); + } + + public void gradeStudent(Student student, Course course, double grade) { + if (this.getName().equals(course.getTeacher())) { + if (student.getEnrolledCourse().equals(course.getName())) { + student.setGrades(grade); + course.recordGrade(student, grade); + } else { + System.out.println(student.getName() + " is not studing in this course!"); + } + } else { + System.out.println(this.getName() + " is not teaching this course"); + } + } +} diff --git a/src/main/java/lessons/lesson05/onlineQuiz/MainQuiz.java b/src/main/java/lessons/lesson05/onlineQuiz/MainQuiz.java new file mode 100644 index 0000000..897e26b --- /dev/null +++ b/src/main/java/lessons/lesson05/onlineQuiz/MainQuiz.java @@ -0,0 +1,22 @@ +package lessons.lesson05.onlineQuiz; + +public class MainQuiz { + public static void main(String[] args) { + Quiz quiz = new Quiz("Java Basics"); + quiz.addQuestion(new MultipleChoiceQuestion("What is JVM?", "Java virtual machine", 10)); + quiz.addQuestion(new MultipleChoiceQuestion("What is the main purpose of the JVM?", "Execution", 10)); + quiz.addQuestion(new MultipleChoiceQuestion("What concept allows one class to inherit from another?", "Inheritance", 10)); + quiz.addQuestion(new MultipleChoiceQuestion("What keyword creates an instance of a class?", "New", 10)); + quiz.addQuestion(new MultipleChoiceQuestion("Which keyword is used to inherit a class in Java?\nA) implement\nB) inherits\nC) extends\nD) import", "C", 5)); + + Team team = new Team("LABUBU", 0); + Team team1 = new Team("SPINER", 0); + + quiz.addTeam(team); + quiz.addTeam(team1); + + quiz.startQuiz(); + + quiz.showResults(); + } +} diff --git a/src/main/java/lessons/lesson05/onlineQuiz/MultipleChoiceQuestion.java b/src/main/java/lessons/lesson05/onlineQuiz/MultipleChoiceQuestion.java new file mode 100644 index 0000000..bc72855 --- /dev/null +++ b/src/main/java/lessons/lesson05/onlineQuiz/MultipleChoiceQuestion.java @@ -0,0 +1,31 @@ +package lessons.lesson05.onlineQuiz; + +import java.util.ArrayList; + +public class MultipleChoiceQuestion extends Question { + private ArrayList options = new ArrayList<>(); + + public MultipleChoiceQuestion(String text, String correctAnswer, int points) { + super(text, points); + setCorrectAnswer(correctAnswer); + } + + @Override + public void ask() { + System.out.println("Answer for this question: " + getText() + "\nYou need to choose only one answer. (A-D)"); + } + + @Override + public boolean checkAnswer(String answer) { + return getCorrectAnswer().equalsIgnoreCase(answer); + } + +// public ArrayList getOptions() { +// return options; +// } +// +// public void setOptions(ArrayList options) { +// this.options = options; +// } +} + diff --git a/src/main/java/lessons/lesson05/onlineQuiz/Question.java b/src/main/java/lessons/lesson05/onlineQuiz/Question.java new file mode 100644 index 0000000..e948064 --- /dev/null +++ b/src/main/java/lessons/lesson05/onlineQuiz/Question.java @@ -0,0 +1,44 @@ +package lessons.lesson05.onlineQuiz; + +public abstract class Question { + private String text; + private String correctAnswer; + private int points; + + public Question(String text, int points) { + this.text = text; + this.points = points; + } + + public void ask() { + System.out.println("Answer for this question: " + text); + } + + public boolean checkAnswer(String answer) { + return correctAnswer.equalsIgnoreCase(answer); + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + public String getText() { + return text; + } + + public String getCorrectAnswer() { + return correctAnswer; + } + + public void setCorrectAnswer(String correctAnswer) { + this.correctAnswer = correctAnswer; + } + + public void setText(String text) { + this.text = text; + } +} diff --git a/src/main/java/lessons/lesson05/onlineQuiz/Quiz.java b/src/main/java/lessons/lesson05/onlineQuiz/Quiz.java new file mode 100644 index 0000000..f62434d --- /dev/null +++ b/src/main/java/lessons/lesson05/onlineQuiz/Quiz.java @@ -0,0 +1,68 @@ +package lessons.lesson05.onlineQuiz; + +import java.util.ArrayList; +import java.util.Scanner; + +public class Quiz { + private String title; + private ArrayList questions = new ArrayList<>(); + private ArrayList teams = new ArrayList<>(); + + public Quiz(String title) { + this.title = title; + } + + public void addQuestion(Question question) { + questions.add(question); + } + + public void addTeam(Team team) { + teams.add(team); + } + + public void startQuiz() { + System.out.println("The Quiz of " + title + " is started! Two teams will be versus each other" + "\nEvery question has their individual points"); + Scanner sc = new Scanner(System.in); + + for (int q = 0; q < questions.size(); q++) { + Question question = questions.get(q); + + for (int t = 0; t < teams.size(); t++) { + + Team currentTeam = teams.get(t % teams.size()); + System.out.println("Question " + q + " - answers team " + currentTeam.getName()); + + System.out.println(question.getText()); + String answer = sc.nextLine().trim().toUpperCase(); +// if (answer.isEmpty()) { +// System.out.println("Please, input answer!"); +// continue; +// } + + if (question.checkAnswer(answer)) { + currentTeam.addScore(question.getPoints()); + System.out.println("Correct! " + currentTeam.getName() + " got " + question.getPoints() + " points!"); + } else { + System.out.println("Wrong! 0 points."); + } + } + } + } + + + public void showResults() { + System.out.println("\nQuiz results for " + "\"" + title + "\""); + int maxScore = 0; + for (Team team : teams) { + System.out.println("Team " + team.getName() + ": " + team.getScore() + " scores"); + if (team.getScore() > maxScore) { + maxScore = team.getScore(); + } + } + for (Team team : teams) { + if (team.getScore() == maxScore) { + System.out.println("The winner of " + "\"" + title + "\"" + " is " + team.getName()); + } + } + } +} diff --git a/src/main/java/lessons/lesson05/onlineQuiz/Team.java b/src/main/java/lessons/lesson05/onlineQuiz/Team.java new file mode 100644 index 0000000..6437c9c --- /dev/null +++ b/src/main/java/lessons/lesson05/onlineQuiz/Team.java @@ -0,0 +1,32 @@ +package lessons.lesson05.onlineQuiz; + +import lessons.lesson05.educationCentre.Student; + +import java.util.ArrayList; + +public class Team { + private String name; + private ArrayList members = new ArrayList<>(); + private int score; + + public Team(String name, int score) { + this.name = name; + this.score = score; + } + + public void addMember(Student student) { + members.add(student); + } + + public void addScore(int points) { + score += points; + } + + public int getScore() { + return score; + } + + public String getName() { + return name; + } +}