Added Faculty management
This commit is contained in:
@@ -2,9 +2,10 @@ package org.lumijiez.base;
|
||||
|
||||
import org.lumijiez.enums.StudyField;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class Faculty {
|
||||
public class Faculty implements Serializable {
|
||||
|
||||
public Faculty(String name, String abbreviation, StudyField field) {
|
||||
this.name = name;
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Student implements Serializable {
|
||||
private FullStudentData FSD;
|
||||
private final List<Grade> grades = new ArrayList<>();
|
||||
|
||||
|
||||
// Student stores a reference to its own Group and Faculty, bidirectional association
|
||||
|
||||
public Faculty getFaculty() {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.lumijiez.enums;
|
||||
|
||||
public enum StudyField {
|
||||
import java.io.Serializable;
|
||||
|
||||
public enum StudyField implements Serializable {
|
||||
DEFAULT_UNASSIGNED("Unassigned", "None"),
|
||||
MECHANICAL_ENGINEERING("Mechanical Engineering", "ME"),
|
||||
SOFTWARE_ENGINEERING("Software Engineering", "FAF"),
|
||||
FOOD_TECHNOLOGY("Food Technology", "FT"),
|
||||
|
||||
@@ -25,7 +25,6 @@ public class StudentManagementGUI {
|
||||
int centerY = (int) ((screenSize.getHeight() - frame.getHeight()) / 2);
|
||||
frame.setLocation(centerX, centerY);
|
||||
|
||||
|
||||
JPanel mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
|
||||
@@ -37,6 +36,21 @@ public class StudentManagementGUI {
|
||||
|
||||
mainPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
String[] options = {"Option 1", "Option 2", "Option 3"};
|
||||
JComboBox<String> dropdown = new JComboBox<>(options);
|
||||
|
||||
JButton button = new JButton("Show Selected Option");
|
||||
|
||||
button.addActionListener(e -> {
|
||||
String selectedOption = (String) dropdown.getSelectedItem();
|
||||
System.out.println(selectedOption);
|
||||
});
|
||||
|
||||
button.setSize(new Dimension(100, 100));
|
||||
|
||||
mainPanel.add(dropdown);
|
||||
mainPanel.add(button);
|
||||
|
||||
JPanel buttonPanel = new JPanel(new GridLayout(0, 1));
|
||||
|
||||
JButton showStudentsBtn = new JButton("Show Students");
|
||||
|
||||
@@ -43,8 +43,11 @@ public class AddStudentForm extends JFrame {
|
||||
String faculty = facultyField.getText();
|
||||
FullStudentData data = new FullStudentData(name, surname, group, faculty);
|
||||
if (!name.isEmpty() && !surname.isEmpty() && !group.isEmpty() && !faculty.isEmpty()) {
|
||||
sv.getFm().getGm().getSm().addStudent(data);
|
||||
sv.getFm().getGm().getSm().addStudent(data, sv);
|
||||
outputTextArea.setText("===== Students =====\n" + sv.getStudentsText());
|
||||
System.out.println(data);
|
||||
System.out.println("LOL");
|
||||
System.out.println(sv.getStudentsText());
|
||||
this.dispose();
|
||||
} else JOptionPane.showMessageDialog(this, "Please fill in all fields.");
|
||||
});
|
||||
|
||||
62
Lab2/src/main/java/org/lumijiez/managers/StudentManager.java
Normal file
62
Lab2/src/main/java/org/lumijiez/managers/StudentManager.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package org.lumijiez.managers;
|
||||
|
||||
import org.lumijiez.base.Faculty;
|
||||
import org.lumijiez.base.Group;
|
||||
import org.lumijiez.base.Student;
|
||||
import org.lumijiez.util.FullStudentData;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.lumijiez.enums.StudyField.DEFAULT_UNASSIGNED;
|
||||
|
||||
public class StudentManager implements Serializable {
|
||||
private final List<Student> students = new ArrayList<>();
|
||||
|
||||
public void addStudent(FullStudentData data, Supervisor sv) {
|
||||
Faculty faculty;
|
||||
Group group;
|
||||
|
||||
if (Objects.isNull(sv.getFm().getFaculty(data.faculty()))) {
|
||||
Faculty newFaculty = new Faculty(data.faculty(), DEFAULT_UNASSIGNED.getAbbreviation(), DEFAULT_UNASSIGNED);
|
||||
sv.getFm().addFaculty(newFaculty);
|
||||
faculty = newFaculty;
|
||||
} else {
|
||||
faculty = sv.getFm().getFaculty(data.faculty());
|
||||
}
|
||||
|
||||
if (Objects.isNull(sv.getFm().getGm().getGroup(data.group()))) {
|
||||
Group newGroup = new Group("Unassigned");
|
||||
sv.getFm().getGm().addGroup(newGroup);
|
||||
group = newGroup;
|
||||
} else {
|
||||
group = sv.getFm().getGm().getGroup(data.group());
|
||||
}
|
||||
|
||||
Student newStudent = new Student(data.name(), data.surname(), group, faculty);
|
||||
students.add(newStudent);
|
||||
}
|
||||
|
||||
public List<Student> getStudents() {
|
||||
return students;
|
||||
}
|
||||
|
||||
public Student getStudent(FullStudentData data) {
|
||||
for (Student st : students) {
|
||||
if (st.getFSD().equals(data)) return st;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void deleteStudent(FullStudentData data) {
|
||||
students.removeIf(student ->
|
||||
student.getName().equals(data.name()) &&
|
||||
student.getSurname().equals(data.surname()) &&
|
||||
student.getGroup().getName().equals(data.group()) &&
|
||||
student.getFaculty().getName().equals(data.faculty())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,10 +17,8 @@ public class Supervisor implements Serializable {
|
||||
|
||||
public String getStudentsText() {
|
||||
StringBuilder info = new StringBuilder();
|
||||
for (Group group : fm.getGm().getGroups()) {
|
||||
for (Student student : group.getStudents()) {
|
||||
info.append(student.getFullname()).append(" ").append(student.getGroup().getName()).append("\n");
|
||||
}
|
||||
for (Student st : fm.getGm().getSm().getStudents()) {
|
||||
info.append(st.getFullname()).append(" ").append(st.getGroup().getName()).append("\n");
|
||||
}
|
||||
return info.toString();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.lumijiez.util;
|
||||
|
||||
|
||||
import org.lumijiez.base.Faculty;
|
||||
import java.io.Serializable;
|
||||
|
||||
// Helper class for easier management of names, surnames, and groups
|
||||
public class FullStudentData {
|
||||
public class FullStudentData implements Serializable {
|
||||
private final String name;
|
||||
private final String surname;
|
||||
private final String groupName;
|
||||
@@ -35,9 +35,14 @@ public class FullStudentData {
|
||||
}
|
||||
|
||||
public boolean equals(FullStudentData data) {
|
||||
return this.name.equals(data.name())
|
||||
&& this.surname.equals(data.surname())
|
||||
&& this.groupName.equals(data.group())
|
||||
&& this.facultyName.equals(data.faculty());
|
||||
return this.name.equals(data.name())
|
||||
&& this.surname.equals(data.surname())
|
||||
&& this.groupName.equals(data.group())
|
||||
&& this.facultyName.equals(data.faculty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + " " + surname + " " + groupName + " " + facultyName + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user