Home / Expert Answers / Computer Science / here-39-s-my-coursegradebook-java-code-import-java-util-arraylist-import-java-util-hashmap-import-pa168

(Solved): Here's my Coursegradebook.java code import java.util.ArrayList; import java.util.HashMap; import ...



Here's my Coursegradebook.java code

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Map;

import java.util.TreeSet;

public class CourseGradebook extends Gradebook {

private HashMap<String, HashMap<Integer, Double>> gradebookData;

public CourseGradebook() {

gradebookData = new HashMap<>();

}

// Override the setScore method from the Gradebook class

@Override

public void setScore(String assignment, int studentID, double score) {

HashMap<Integer, Double> studentScores = gradebookData.get(assignment);

if (studentScores == null) {

studentScores = new HashMap<>();

gradebookData.put(assignment, studentScores);

}

studentScores.put(studentID, score);

}

public Double getScore(String assignment, int studentID) {

HashMap<Integer, Double> studentScores = gradebookData.get(assignment);

if (studentScores == null) {

return Double.NaN;

}

return studentScores.getOrDefault(studentID, Double.NaN);

}

public HashMap<Integer, Double> getAssignmentScores(String assignment) {

HashMap<Integer, Double> studentScores = gradebookData.get(assignment);

if (studentScores == null) {

return new HashMap<>();

}

return new HashMap<>(studentScores);

}

public ArrayList<String> getSortedAssignmentNames() {

TreeSet<String> assignmentNames = new TreeSet<>(gradebookData.keySet());

return new ArrayList<>(assignmentNames);

}

public ArrayList<Integer> getSortedStudentIDs() {

TreeSet<Integer> studentIDs = new TreeSet<>();

for (Map<Integer, Double> scores : gradebookData.values()) {

studentIDs.addAll(scores.keySet());

}

return new ArrayList<>(studentIDs);

}

public HashMap<String, Double> getStudentScores(int studentID) {

HashMap<String, Double> studentScores = new HashMap<>();

for (String assignment : gradebookData.keySet()) {

Double score = getScore(assignment, studentID);

if (!score.isNaN()) {

studentScores.put(assignment, score);

}

}

return studentScores;

}

public HashMap<String, Double> getStudentScores(Integer studentID) {

return getStudentScores(studentID.intValue());

}

}

}

I get this error when I try to run my code

CourseGradebook.java:70: error: class, interface, or enum expected

}

^

1 error



We have an Answer from Expert

View Expert Answer

Expert Answer



ANSWER:

The following are the ways to correct the error in your code:

Step 1: Identify the error.

The error message suggests a problem with an unexpected closing brace. It indicates to line 70, which has an extra closing brace.

Step 2: Identify the issue.

A closing brace () is used in Java to indicate the end of a class, function, or block of code. The compiler interprets the extra closing bracket at the end of your code as an unusual token, resulting in the error.

Step 3: Remove the additional closure brace.

Simply remove the extra closing brace at the end of your code to repair the mistake. It isn't supposed to be there and is generating the compilation issue.

Determine the error: Line 70 has an unexpected closing brace, according to the error notice.
Recognise the problem: Because the extra closing brace does not belong there, the compiler flags it as a mistake.
Remove the additional closure brace: Simply remove the extra closing brace at the end of your code.
Recompile: Save the repaired code and recompile it to ensure that the mistake is no longer there.
You can repair the mistake in your code and properly compile it by following these instructions.



We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe