Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finished task 4 #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
9 changes: 8 additions & 1 deletion src/main/java/app/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
29 changes: 17 additions & 12 deletions src/main/java/app/gui/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(() -> {
Expand All @@ -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");
Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand Down