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
25 changes: 20 additions & 5 deletions src/main/java/api/MongoGradeDataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,29 @@ public Team getMyTeam() {
.addHeader(TOKEN, getAPIToken())
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
.build();

final Response response;
final JSONObject responseBody;

try {
// TODO Task 3b: Implement the logic to get the team information
// HINT 1: Look at the formTeam method to get an idea on how to parse the response
// HINT 2: You may find it useful to just initially print the contents of the JSON
// then work on the details of how to parse it.
return null;
final Response response = client.newCall(request).execute();
final JSONObject responseBody = new JSONObject(response.body().string());
if(responseBody.getInt(STATUS_CODE) == SUCCESS_CODE){
final JSONObject team = responseBody.getJSONObject("team");
final JSONArray membersArray = team.getJSONArray("members");
final String[] members = new String[membersArray.length()];
for (int i = 0; i < membersArray.length(); i++) {
members[i] = membersArray.getString(i);
}
return Team.builder()
.name(team.getString(NAME))
.members(members)
.build();
}else {
throw new RuntimeException(responseBody.getString(MESSAGE));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
12 changes: 11 additions & 1 deletion src/main/java/usecase/GetAverageGradeUseCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import entity.Grade;
import entity.Team;

import java.util.List;

/**
* GetAverageGradeUseCase class.
*/
Expand All @@ -28,7 +30,15 @@ public float getAverageGrade(String course) {
// Call the API to get all the grades for the course for all your team members
// TODO Task 3a: Complete the logic of calculating the average course grade for
// your team members. Hint: the getGrades method might be useful.

for(String member : team.getMembers()) {
Grade[] grades = gradeDataBase.getGrades(member);
for(Grade grade : grades) {
if(grade.getCourse().equals(course)) {
sum += grade.getGrade();
count++;
}
}
}
if (count == 0) {
return 0;
}
Expand Down