-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
185 lines (153 loc) · 5.48 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import java.time.LocalDate;
import java.util.*;
import javax.swing.JOptionPane;
// Student class
class Student {
private int id;
private String name;
private String email;
public Student(int id, String name, String email) {
this.id = id;
this.name = name;
this.email = email;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
}
// Course class
class Course {
private int courseId;
private String courseName;
public Course(int courseId, String courseName) {
this.courseId = courseId;
this.courseName = courseName;
}
public int getCourseId() {
return courseId;
}
public String getCourseName() {
return courseName;
}
}
// Session class
class Session {
private int sessionId;
private Course course;
private LocalDate date;
private Map<Student, Boolean> attendanceRecord;
public Session(int sessionId, Course course, LocalDate date) {
this.sessionId = sessionId;
this.course = course;
this.date = date;
this.attendanceRecord = new HashMap<>();
}
public Course getCourse() {
return course;
}
public LocalDate getDate() {
return date;
}
public Map<Student, Boolean> getAttendanceRecord() {
return attendanceRecord;
}
}
// AttendanceSystem class
class AttendanceSystem {
private List<Student> students;
private List<Course> courses;
private List<Session> sessions;
public AttendanceSystem() {
students = new ArrayList<>();
courses = new ArrayList<>();
sessions = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public void addCourse(Course course) {
courses.add(course);
}
public void startSession(Course course, LocalDate date) {
int sessionId = sessions.size() + 1;
Session session = new Session(sessionId, course, date);
sessions.add(session);
}
public void markAttendance(Session session, Student student, boolean status) {
if (sessions.contains(session) && students.contains(student)) {
session.getAttendanceRecord().put(student, status);
} else {
throw new IllegalArgumentException("Session or student not found.");
}
}
public List<Session> getSessions() {
return sessions;
}
public Student findStudentByName(String name) {
for (Student student : students) {
if (student.getName().equalsIgnoreCase(name)) {
return student;
}
}
return null; // Return null if student not found
}
public List<Course> getCourses() {
return courses;
}
}
public class Main {
public static void main(String[] args) {
// Creating an instance of the AttendanceSystem
AttendanceSystem attendanceSystem = new AttendanceSystem();
// Adding students
Student student1 = new Student(40080, "Gayathri Yerra", "[email protected]");
Student student2 = new Student(40069, "Laasika Anuga", "[email protected]");
Student student3 = new Student(30385, "Gayathri Vemali", "[email protected]");
Student student4 = new Student(30120, "Charan Veeravalli", "[email protected]");
attendanceSystem.addStudent(student1);
attendanceSystem.addStudent(student2);
attendanceSystem.addStudent(student3);
attendanceSystem.addStudent(student4);
// Adding courses
Course course1 = new Course(101, "Java Programming");
Course course2 = new Course(102, "Data Structures");
Course course3 = new Course(103, "Digital Design");
attendanceSystem.addCourse(course1);
attendanceSystem.addCourse(course2);
attendanceSystem.addCourse(course3);
// Starting sessions
LocalDate sessionDate = LocalDate.now(); // Current date
attendanceSystem.startSession(course1, sessionDate);
attendanceSystem.startSession(course2, sessionDate);
attendanceSystem.startSession(course3, sessionDate);
// Input student name
String studentName = JOptionPane.showInputDialog("Enter student name:");
// Find student
Student student = attendanceSystem.findStudentByName(studentName);
if (student != null) {
StringBuilder attendanceRecord = new StringBuilder();
attendanceRecord.append("Attendance for ").append(student.getName()).append(":\n");
// Iterate through courses and mark attendance
for (Course course : attendanceSystem.getCourses()) {
Session session = attendanceSystem.getSessions().get(course.getCourseId() - 101);
attendanceSystem.markAttendance(session, student, Math.random() < 0.8); // Randomly mark attendance
attendanceRecord.append(session.getCourse().getCourseName()).append(": ");
if (session.getAttendanceRecord().get(student)) {
attendanceRecord.append("Present\n");
} else {
attendanceRecord.append("Absent\n");
}
}
// Display attendance record in a dialog box
JOptionPane.showMessageDialog(null, attendanceRecord.toString());
} else {
JOptionPane.showMessageDialog(null, "Student not found.");
}
}
}