diff --git a/src/main/java/app/Config.java b/src/main/java/app/Config.java index 12df0fd..77b684e 100644 --- a/src/main/java/app/Config.java +++ b/src/main/java/app/Config.java @@ -65,5 +65,12 @@ public GetAverageGradeUseCase getAverageGradeUseCase() { return new GetAverageGradeUseCase(gradeDataBase); } - // TODO Task 4: add code for the new GetTopGradeUseCase following the same pattern as the other use cases above. + /** + * Get the GetTopGradeUseCase object. + * @return GetTopGradeUseCase object. + */ + public GetTopGradeUseCase getTopGradeUseCase() { + return new GetTopGradeUseCase(gradeDataBase); + } + } diff --git a/src/main/java/app/gui/Application.java b/src/main/java/app/gui/Application.java index a083b09..9bd4ad3 100644 --- a/src/main/java/app/gui/Application.java +++ b/src/main/java/app/gui/Application.java @@ -17,12 +17,7 @@ import api.MongoGradeDataBase; import app.Config; import entity.Grade; -import usecase.FormTeamUseCase; -import usecase.GetAverageGradeUseCase; -import usecase.GetGradeUseCase; -import usecase.JoinTeamUseCase; -import usecase.LeaveTeamUseCase; -import usecase.LogGradeUseCase; +import usecase.*; /** * GUI class to run the GUI for the Grade App. @@ -51,6 +46,7 @@ public static void main(String[] args) { final JoinTeamUseCase joinTeamUseCase = config.joinTeamUseCase(); final LeaveTeamUseCase leaveTeamUseCase = config.leaveTeamUseCase(); final GetAverageGradeUseCase getAverageGradeUseCase = config.getAverageGradeUseCase(); + final GetTopGradeUseCase getTopGradeUseCase = config.getTopGradeUseCase(); // this is the code that runs to set up our GUI SwingUtilities.invokeLater(() -> { @@ -66,7 +62,7 @@ public static void main(String[] args) { final JPanel logGradeCard = createLogGradeCard(frame, logGradeUseCase); final JPanel formTeamCard = createFormTeamCard(frame, formTeamUseCase); final JPanel joinTeamCard = createJoinTeamCard(frame, joinTeamUseCase); - final JPanel manageTeamCard = createManageTeamCard(frame, leaveTeamUseCase, getAverageGradeUseCase); + final JPanel manageTeamCard = createManageTeamCard(frame, leaveTeamUseCase, getAverageGradeUseCase, getTopGradeUseCase); cardPanel.add(defaultCard, "DefaultCard"); cardPanel.add(getGradeCard, "GetGradeCard"); @@ -237,16 +233,15 @@ private static JPanel createJoinTeamCard(JFrame jFrame, JoinTeamUseCase joinTeam return theCard; } - // TODO Task 4: modify this method so that it takes in a getTopGradeUseCase - // Note: this will require you to update the code which calls this method. + private static JPanel createManageTeamCard(JFrame jFrame, LeaveTeamUseCase leaveTeamUseCase, - GetAverageGradeUseCase getAverageGradeUseCase) { + GetAverageGradeUseCase getAverageGradeUseCase, GetTopGradeUseCase getTopGradeUseCase) { final JPanel theCard = new JPanel(); theCard.setLayout(new GridLayout(ROWS, COLS)); final JTextField courseField = new JTextField(20); // make a separate line. final JButton getAverageButton = new JButton("Get Average Grade"); - // TODO Task 4: Add another button for "Get Top Grade" (check the getAverageButton for example) + final JButton getTopGrade = new JButton("Get Top Grade"); final JButton leaveTeamButton = new JButton("Leave Team"); final JLabel resultLabel = new JLabel(); @@ -263,8 +258,18 @@ private static JPanel createManageTeamCard(JFrame jFrame, LeaveTeamUseCase leave JOptionPane.showMessageDialog(jFrame, ex.getMessage()); } }); + getTopGrade.addActionListener(event -> { + final String course1 = courseField.getText(); + try { + final float top = getTopGradeUseCase.getTopGrade(course1); + JOptionPane.showMessageDialog(jFrame, "Top Grade: " + top); + courseField.setText(""); + } + catch (Exception ex) { + JOptionPane.showMessageDialog(jFrame, ex.getMessage()); + } + }); - // TODO Task 4: Add action listener for getTopGrade button, follow example of getAverageButton leaveTeamButton.addActionListener(event -> { try {