-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudyPlannerGUI.java
More file actions
122 lines (95 loc) · 3.58 KB
/
Copy pathStudyPlannerGUI.java
File metadata and controls
122 lines (95 loc) · 3.58 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
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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
class Subject {
String name;
int difficulty;
int chapters;
int completed;
Subject(String name, int difficulty, int chapters, int completed) {
this.name = name;
this.difficulty = difficulty;
this.chapters = chapters;
this.completed = completed;
}
int pending() {
return chapters - completed;
}
}
public class StudyPlannerGUI extends JFrame {
ArrayList<Subject> subjects = new ArrayList<>();
JTextField nameField, diffField, chapField, compField, hoursField;
JTextArea outputArea;
public StudyPlannerGUI() {
setTitle("AI Based Study Planner");
setSize(600, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
add(new JLabel("Subject Name:"));
nameField = new JTextField(20);
add(nameField);
add(new JLabel("Difficulty (1-5):"));
diffField = new JTextField(5);
add(diffField);
add(new JLabel("Total Chapters:"));
chapField = new JTextField(5);
add(chapField);
add(new JLabel("Completed Chapters:"));
compField = new JTextField(5);
add(compField);
JButton addBtn = new JButton("Add Subject");
add(addBtn);
add(new JLabel("Available Study Hours Today:"));
hoursField = new JTextField(10);
add(hoursField);
JButton generateBtn = new JButton("Generate Plan");
add(generateBtn);
outputArea = new JTextArea(20, 45);
add(new JScrollPane(outputArea));
// Add Subject Button Function
addBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
int diff = Integer.parseInt(diffField.getText());
int chap = Integer.parseInt(chapField.getText());
int comp = Integer.parseInt(compField.getText());
subjects.add(new Subject(name, diff, chap, comp));
outputArea.append("Added: " + name + "\n");
nameField.setText("");
diffField.setText("");
chapField.setText("");
compField.setText("");
}
});
// Generate Plan Button Function
generateBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double hours = Double.parseDouble(hoursField.getText());
generatePlan(hours);
}
});
}
// AI Logic
void generatePlan(double hours) {
outputArea.append("\n======= AI GENERATED STUDY PLAN =======\n");
double totalPriority = 0;
for (Subject s : subjects) {
totalPriority += s.difficulty * s.pending();
}
for (Subject s : subjects) {
if (s.pending() == 0) continue;
double priority = s.difficulty * s.pending();
double timeAlloc = (priority / totalPriority) * hours;
outputArea.append(
"\nSubject: " + s.name +
"\nPending Chapters: " + s.pending() +
"\nDifficulty: " + s.difficulty +
String.format("\nAllocated Time: %.2f hours\n", timeAlloc)
);
}
}
public static void main(String[] args) {
new StudyPlannerGUI().setVisible(true);
}
}