Added Faculty management
This commit is contained in:
@@ -2,9 +2,10 @@ package org.lumijiez.base;
|
|||||||
|
|
||||||
import org.lumijiez.enums.StudyField;
|
import org.lumijiez.enums.StudyField;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Faculty {
|
public class Faculty implements Serializable {
|
||||||
|
|
||||||
public Faculty(String name, String abbreviation, StudyField field) {
|
public Faculty(String name, String abbreviation, StudyField field) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class Student implements Serializable {
|
|||||||
private FullStudentData FSD;
|
private FullStudentData FSD;
|
||||||
private final List<Grade> grades = new ArrayList<>();
|
private final List<Grade> grades = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
// Student stores a reference to its own Group and Faculty, bidirectional association
|
// Student stores a reference to its own Group and Faculty, bidirectional association
|
||||||
|
|
||||||
public Faculty getFaculty() {
|
public Faculty getFaculty() {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package org.lumijiez.enums;
|
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"),
|
MECHANICAL_ENGINEERING("Mechanical Engineering", "ME"),
|
||||||
SOFTWARE_ENGINEERING("Software Engineering", "FAF"),
|
SOFTWARE_ENGINEERING("Software Engineering", "FAF"),
|
||||||
FOOD_TECHNOLOGY("Food Technology", "FT"),
|
FOOD_TECHNOLOGY("Food Technology", "FT"),
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public class StudentManagementGUI {
|
|||||||
int centerY = (int) ((screenSize.getHeight() - frame.getHeight()) / 2);
|
int centerY = (int) ((screenSize.getHeight() - frame.getHeight()) / 2);
|
||||||
frame.setLocation(centerX, centerY);
|
frame.setLocation(centerX, centerY);
|
||||||
|
|
||||||
|
|
||||||
JPanel mainPanel = new JPanel();
|
JPanel mainPanel = new JPanel();
|
||||||
mainPanel.setLayout(new BorderLayout());
|
mainPanel.setLayout(new BorderLayout());
|
||||||
|
|
||||||
@@ -37,6 +36,21 @@ public class StudentManagementGUI {
|
|||||||
|
|
||||||
mainPanel.add(scrollPane, BorderLayout.CENTER);
|
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));
|
JPanel buttonPanel = new JPanel(new GridLayout(0, 1));
|
||||||
|
|
||||||
JButton showStudentsBtn = new JButton("Show Students");
|
JButton showStudentsBtn = new JButton("Show Students");
|
||||||
|
|||||||
@@ -43,8 +43,11 @@ public class AddStudentForm extends JFrame {
|
|||||||
String faculty = facultyField.getText();
|
String faculty = facultyField.getText();
|
||||||
FullStudentData data = new FullStudentData(name, surname, group, faculty);
|
FullStudentData data = new FullStudentData(name, surname, group, faculty);
|
||||||
if (!name.isEmpty() && !surname.isEmpty() && !group.isEmpty() && !faculty.isEmpty()) {
|
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());
|
outputTextArea.setText("===== Students =====\n" + sv.getStudentsText());
|
||||||
|
System.out.println(data);
|
||||||
|
System.out.println("LOL");
|
||||||
|
System.out.println(sv.getStudentsText());
|
||||||
this.dispose();
|
this.dispose();
|
||||||
} else JOptionPane.showMessageDialog(this, "Please fill in all fields.");
|
} 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() {
|
public String getStudentsText() {
|
||||||
StringBuilder info = new StringBuilder();
|
StringBuilder info = new StringBuilder();
|
||||||
for (Group group : fm.getGm().getGroups()) {
|
for (Student st : fm.getGm().getSm().getStudents()) {
|
||||||
for (Student student : group.getStudents()) {
|
info.append(st.getFullname()).append(" ").append(st.getGroup().getName()).append("\n");
|
||||||
info.append(student.getFullname()).append(" ").append(student.getGroup().getName()).append("\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return info.toString();
|
return info.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package org.lumijiez.util;
|
package org.lumijiez.util;
|
||||||
|
|
||||||
|
|
||||||
import org.lumijiez.base.Faculty;
|
import java.io.Serializable;
|
||||||
|
|
||||||
// Helper class for easier management of names, surnames, and groups
|
// 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 name;
|
||||||
private final String surname;
|
private final String surname;
|
||||||
private final String groupName;
|
private final String groupName;
|
||||||
@@ -40,4 +40,9 @@ public class FullStudentData {
|
|||||||
&& this.groupName.equals(data.group())
|
&& this.groupName.equals(data.group())
|
||||||
&& this.facultyName.equals(data.faculty());
|
&& this.facultyName.equals(data.faculty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name + " " + surname + " " + groupName + " " + facultyName + "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user