-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudySession.java
More file actions
30 lines (28 loc) · 1.06 KB
/
Copy pathStudySession.java
File metadata and controls
30 lines (28 loc) · 1.06 KB
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
/**
* Java 21 Record for Study Session.
* Implements Comparable taake isko automatically End Time ke hisaab se sort kiya ja sake,
* Weighted Interval Scheduling algorithm ki pehli requirement ke hisab se.
*/
public record StudySession(
String subjectName,
int startTime,
int endTime,
int priority
) implements Comparable<StudySession> {
// Compact Constructor Object banne se pehle data validate karta hai
public StudySession {
// Validation: Start time hamesha End time se chota hoga
if (startTime >= endTime) {
throw new IllegalArgumentException("Error: Start time must be strictly less than end time.");
}
// Validation: Priority negative nahi ho sakti
if (priority < 0) {
throw new IllegalArgumentException("Error: Priority cannot be negative.");
}
}
// override method DP algorithm ke liye sessions ko ascending order mein sort karna
@Override
public int compareTo(StudySession other) {
return Integer.compare(this.endTime, other.endTime);
}
}