Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 99 additions & 3 deletions src/CurriculumGui.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import java.awt.*;

import java.util.ArrayList;
import java.util.Objects;

public class CurriculumGUI {
private JFrame frame;
private JComboBox<String> yearDropdown, termDropdown;
private JButton fillButton, saveButton;
private JTable courseTable;
private DefaultTableModel model;
private CurriculumManager curriculumManager;

public CurriculumGUI(CurriculumManager curriculumManager) {
this.curriculumManager = curriculumManager;

frame = new JFrame("Curriculum Monitoring");
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Center the frame on the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int xPos = (screenSize.width - frame.getWidth()) / 2;
int yPos = (screenSize.height - frame.getHeight()) / 2;
frame.setLocation(xPos, yPos);

// Create year and term dropdowns
yearDropdown = new JComboBox<>(new String[]{"1", "2", "3", "4"});
termDropdown = new JComboBox<>(new String[]{"First Sem", "Second Sem", "Short Term"});

// Create buttons for filling and saving curriculum
fillButton = new JButton("Fill Curriculum");
fillButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
fillCurriculum();

public class CurriculumGui extends JFrame {
private ArrayList<Course> filtered = new ArrayList<>();

Expand Down Expand Up @@ -115,12 +152,72 @@ private void setMenuPanel() {
}
} else {
JOptionPane.showMessageDialog(this, "You entered a valid Integer", "Error", JOptionPane.ERROR_MESSAGE);

}
textField.setText("");
});
saveButton = new JButton("Save Curriculum");
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveCurriculum();
}
});

// Create the course table
courseTable = new JTable();
JScrollPane scrollPane = new JScrollPane(courseTable);

// Create the button panel
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(fillButton);
buttonPanel.add(saveButton);

// Create the combo box panel
JPanel comboBoxPanel = new JPanel();
comboBoxPanel.setLayout(new GridLayout(1, 2));
comboBoxPanel.add(yearDropdown);
comboBoxPanel.add(termDropdown);

// Add panels to the frame
frame.add(comboBoxPanel, BorderLayout.NORTH);
frame.add(buttonPanel, BorderLayout.SOUTH);
frame.add(scrollPane, BorderLayout.CENTER);

// Show the frame
frame.setVisible(true);
}

private void fillCurriculum() {
String selectedYear = (String) yearDropdown.getSelectedItem();
String selectedTerm = (String) termDropdown.getSelectedItem();
curriculumManager.fillCurriculum(selectedYear, selectedTerm);
displayCurriculum();
}
private void saveCurriculum() {
curriculumManager.saveCurriculum();
}

public void displayCurriculum()
ArrayList<Course> curriculum = curriculumManager.getCurriculum();
Object[][] data = new Object[curriculum.size()][6];

for (int i = 0; i < curriculum.size(); i++) {
Course course = curriculum.get(i);
data[i][0] = course.getYear();
data[i][1] = course.getTerm();
data[i][2] = course.getCourseNumber();
data[i][3] = course.getDescriptiveTitle();
data[i][4] = course.getUnits();
data[i][5] = course.getGrade() == 0 ? "Not Yet Taken" : course.getGrade();
}

String[] columnNames = {"Year", "Term", "Course Number", "Course Title", "Units", "Grade"};
model = new DefaultTableModel(data, columnNames);
courseTable.setModel(model);
}
public static void main(String[] args) {
CurriculumManager curriculumManager = new CurriculumManagement();
SwingUtilities.invokeLater(() -> new CurriculumGUI(curriculumManager));

//-----------------------------------------------CHOICE ONE---------------------------------------------------------

Expand Down Expand Up @@ -664,9 +761,8 @@ private int getYear(String selectedItem) {
case "3rd Year" -> 3;
default -> 4;
};
}


}

private void calculateGPA() {
}
Expand Down
35 changes: 30 additions & 5 deletions src/CurriculumManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,43 @@ public class CurriculumManagement implements CurriculumManager{
private static final String fileName = "Curriculum.txt";
private static final ArrayList<Course> courses = new ArrayList<>();


/**
* Fills the Arraylist with Courses
*/
@Override
public void fillCurriculum() {
public void fillCurriculum(String year, String term) {
courses.clear();
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
String line;

while ((line = reader.readLine()) != null) {

while ((line = reader.readLine()) != null){

String[] courseText = line.split(",(?!\\s)");
Course course = readCourse(courseText);
courses.add(course);

// Filter out courses based on selected year and term
if (Byte.toString(course.getYear()).equals(year) && course.getTerm().equals(term)) {
courses.add(course);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}

// Display the filtered curriculum
displayCurriculum(courses);
}

private void displayCurriculum(ArrayList<Course> courses) {
}


@Override
public void fillCurriculum() {

}
/**
* Reads the courses details in array of String and returns an object of Course
* @param courseText the details of the course (units, title, course no.)
Expand Down Expand Up @@ -54,7 +72,6 @@ public ArrayList<Course> getCurriculum() {
return courses;
}


/**
* edits the grades of the courses of a specific term of a year
* @param grades the ArrayList of grades to be set
Expand All @@ -67,10 +84,15 @@ public void editGrade(ArrayList<Byte> grades, int year, String term) throws Valu
int count = 0;
for (Course course : courses){
if (course.getYear() == year && course.getTerm().equals(term)){


if (notValid(Float.valueOf(grades.get(count)), (byte) 65, (byte) 99)){

byte grade = grades.get(count);
if (grade == 0){
course.setGrade((byte) 0);
} else if (notValid((float) grade, (byte) 65, (byte) 99)){

throw new ValueOutOfRangeException();
} else {
course.setGrade(grade);
Expand Down Expand Up @@ -131,7 +153,6 @@ public double calculateGPA() {
return score/units;
}


/**
* Saves the changes made of the user in his Curriculum monitoring
*/
Expand All @@ -152,6 +173,9 @@ public void saveCurriculum() {
}

public void reset() {

courses.clear();

try (BufferedReader reader = new BufferedReader(new FileReader("Original Curriculum.txt"));
BufferedWriter writer = new BufferedWriter(new FileWriter("Curriculum.txt"))) {

Expand All @@ -164,6 +188,7 @@ public void reset() {
}
courses.clear();
fillCurriculum();

}

}
Expand Down