diff --git a/lessons/src/main/java/lessons/lesson05/App.java b/lessons/src/main/java/lessons/lesson05/App.java new file mode 100644 index 0000000..fca7bea --- /dev/null +++ b/lessons/src/main/java/lessons/lesson05/App.java @@ -0,0 +1,30 @@ +package Lesson5; + +/** + * @author Shohjahon + * @version 1.0 + */ + +public class App { + public static void main(String[] args) { + Teacher teacher = new Teacher("Shohjahon", "01"); + + Course course = new Course("1", "Java", teacher); + + Student student1 = new Student("Ali", "001"); + Student student2 = new Student("Bob", "002"); + course.addStudent(student1); + course.addStudent(student2); + + course.markAttendance("001", "2025-10-03", true); + course.markAttendance("002", "2025-10-03", false); + + course.assignScore("001", 95.0); + course.assignScore("002", 88.5); + + course.displayCourseDetails(); + + student1.displayAttend(); + student2.displayAttend(); + } +} diff --git a/lessons/src/main/java/lessons/lesson05/Course.java b/lessons/src/main/java/lessons/lesson05/Course.java new file mode 100644 index 0000000..72f7204 --- /dev/null +++ b/lessons/src/main/java/lessons/lesson05/Course.java @@ -0,0 +1,47 @@ +package Lesson5; + +import java.util.ArrayList; +import java.util.List; + +public class Course { + private String courseId; + private String courseName; + private Teacher teacher; + private List< Student > students = new ArrayList<>(); + + public Course( String courseId, String courseName, Teacher teacher ) { + this.courseId = courseId; + this.courseName = courseName; + this.teacher = teacher; + } + + public void addStudent( Student student ) { + students.add( student ); + } + + public void markAttendance( String studentId, String date, boolean present ) { + for ( Student student : students ) { + if ( student.getId().equals( studentId ) ) { + student.markAttendance( date, present ); + break; + } + } + } + + public void assignScore( String studentId, double score ) { + for ( Student student : students ) { + if ( student.getId().equals( studentId ) ) { + student.setScore( score ); + break; + } + } + } + + public void displayCourseDetails() { + System.out.println( "\nCourse: " + courseName + " (ID: " + courseId + ")" ); + teacher.displayInfo(); + for ( Student s : students ) { + s.displayInfo(); + } + } +} diff --git a/lessons/src/main/java/lessons/lesson05/Person.java b/lessons/src/main/java/lessons/lesson05/Person.java new file mode 100644 index 0000000..7d09e8f --- /dev/null +++ b/lessons/src/main/java/lessons/lesson05/Person.java @@ -0,0 +1,15 @@ +package Lesson5; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +public abstract class Person { + private String name; + private String id; + + public abstract void displayInfo(); +} diff --git a/lessons/src/main/java/lessons/lesson05/Student.java b/lessons/src/main/java/lessons/lesson05/Student.java new file mode 100644 index 0000000..0b0157c --- /dev/null +++ b/lessons/src/main/java/lessons/lesson05/Student.java @@ -0,0 +1,35 @@ +package Lesson5; + +import lombok.Getter; +import lombok.Setter; + +import java.util.HashMap; +import java.util.Map; + +public class Student extends Person { + private Map attendanceLog = new HashMap<>(); + @Getter + @Setter + private double score; + + public Student(String name, String id) { + super(name, id); + } + + public void markAttendance(String date, boolean present) { + attendanceLog.put(date, present); + } + + public void displayAttend() { + System.out.printf("Attendance for %s:", getName()); + for (Map.Entry entry : attendanceLog.entrySet()) { + String status = entry.getValue() ? "Present" : "Absent"; + System.out.printf(" %s -> %s%n", entry.getKey(), status); + } + } + + @Override + public void displayInfo() { + System.out.println("Student: " + getName() + " (ID: " + getId() + "), Score: " + score); + } +} diff --git a/lessons/src/main/java/lessons/lesson05/Teacher.java b/lessons/src/main/java/lessons/lesson05/Teacher.java new file mode 100644 index 0000000..ebded4d --- /dev/null +++ b/lessons/src/main/java/lessons/lesson05/Teacher.java @@ -0,0 +1,12 @@ +package Lesson5; + +public class Teacher extends Person { + public Teacher(String name, String id) { + super(name, id); + } + + @Override + public void displayInfo() { + System.out.println("Instructor: " + getName() + " (ID: " + getId() + ")"); + } +}