Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions lessons/src/main/java/lessons/lesson05/App.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
47 changes: 47 additions & 0 deletions lessons/src/main/java/lessons/lesson05/Course.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
15 changes: 15 additions & 0 deletions lessons/src/main/java/lessons/lesson05/Person.java
Original file line number Diff line number Diff line change
@@ -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();
}
35 changes: 35 additions & 0 deletions lessons/src/main/java/lessons/lesson05/Student.java
Original file line number Diff line number Diff line change
@@ -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<String, Boolean> 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<String, Boolean> 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);
}
}
12 changes: 12 additions & 0 deletions lessons/src/main/java/lessons/lesson05/Teacher.java
Original file line number Diff line number Diff line change
@@ -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() + ")");
}
}