Question: Can someone help implement the 3 methods below. Thank you There are 3 other classes, Class CourseGrade (withthe following method: getAverage,getProfessor,getSection,getDepartment,getNumstudent, Map() getGrades), Class Course(with
Can someone help implement the 3 methods below. Thank you
There are 3 other classes, Class CourseGrade (withthe following method: getAverage,getProfessor,getSection,getDepartment,getNumstudent, Map() getGrades), Class Course(with the following methods: getDepartment, getCourse,getSection, equals(Object o)), Class Professor( with the following method: getName, and equals(Object o)).
--------------------------------------here is how the program read data from file----------------------------------------
public Analyze () { ArrayList courseGrades = new ArrayList(); } public void readData (String fileName) throws FileNotFoundException { Scanner s = new Scanner(new File(fileName)); s.nextLine(); while (s.hasNextLine()) { String line = s.nextLine(); String[] data = line.split(","); Professor p = new Professor(data[2]); String course = data[0]; String department = course.substring(0, 4); int courseNumber = Integer.valueOf(course.substring(4, 7)); char special = '\0'; if (course.length() == 8) { special = course.charAt(7); } String section = data[1];
Course c = new Course (department, courseNumber, special, section); CourseGrade cg = new CourseGrade(p, c); cg.updateGrade("A+", Integer.valueOf(data[4])); cg.updateGrade("A", Integer.valueOf(data[5])); cg.updateGrade("A-", Integer.valueOf(data[6])); cg.updateGrade("B+", Integer.valueOf(data[7])); cg.updateGrade("B", Integer.valueOf(data[8])); cg.updateGrade("B-", Integer.valueOf(data[9])); cg.updateGrade("C+", Integer.valueOf(data[10])); cg.updateGrade("C", Integer.valueOf(data[11])); cg.updateGrade("C-", Integer.valueOf(data[12])); cg.updateGrade("D+", Integer.valueOf(data[13])); cg.updateGrade("D", Integer.valueOf(data[14])); cg.updateGrade("D-", Integer.valueOf(data[15])); cg.updateGrade("F", Integer.valueOf(data[16])); cg.updateGrade("W", Integer.valueOf(data[17])); cg.updateGrade("Other", Integer.valueOf(data[18])); courseGrades.add(cg); } s.close(); }
---------------------here is the instruction for the three methods---------------------------------------------------------

----------------here are the three methods i need to implement--------------------------------------
public float getProfessorAverage (Professor p) { return 0; } public float getCourseAverage (Course c, boolean sectionOnly) { return 0; } public float getDepartmentAverage (String department) { return 0; }
---------below are the classes-------------------------
import java.util.HashMap;
import java.util.Map;
class CourseGrade implements Comparable
private Professor professor;
private Course course;
private Map
public CourseGrade(Professor professor, Course course) {
this.professor = professor;
this.course = course;
grades = new HashMap
}
public Professor getProfessor() {
return professor;
}
public Course getCourse() {
return course;
}
public Map
return grades;
}
public void updateGrade(String grade, int numStudents) {
if (grades.containsKey(grade)) {
grades.replace(grade, numStudents);
}
}
public float getAverage() {
int numOfStudents = 0;
int totalStudents = 0;
float total = 0;
for (Map.Entry
numOfStudents = (int) pair.getValue();
switch (pair.getValue().toString()) {
case "A+":
total += numOfStudents * 4.0;
totalStudents += numOfStudents;
break;
case "A":
total += numOfStudents * 4.0;
totalStudents += numOfStudents;
break;
case "A-":
total += numOfStudents * 3.7;
totalStudents += numOfStudents;
break;
case "B+":
total += numOfStudents * 3.3;
totalStudents += numOfStudents;
break;
case "B":
total += numOfStudents * 3.0;
totalStudents += numOfStudents;
break;
case "B-":
total += numOfStudents * 2.7;
totalStudents += numOfStudents;
break;
case "C+":
total += numOfStudents * 2.3;
totalStudents += numOfStudents;
break;
case "C":
total += numOfStudents * 2.0;
totalStudents += numOfStudents;
break;
case "C-":
total += numOfStudents * 1.7;
totalStudents += numOfStudents;
break;
case "D+":
total += numOfStudents * 1.3;
totalStudents += numOfStudents;
break;
case "D":
total += numOfStudents * 1.0;
totalStudents += numOfStudents;
break;
case "D-":
total += numOfStudents * 0.7;
totalStudents += numOfStudents;
break;
case "F":
total += numOfStudents * 0.0;
totalStudents += numOfStudents;
break;
case "W":
total += numOfStudents * 0.0;
totalStudents += numOfStudents;
break;
case "Other":
break;
}
}
return total / totalStudents;
}
public int getNumGrade(String grade) {
return grades.get("A-");
}
public int getNumStudents() {
int numOfStudents = 0;
numOfStudents = grades.entrySet().stream().map((pair) -> (int) pair.getValue()).reduce(numOfStudents,
Integer::sum);
return numOfStudents;
}
public int compareTo(CourseGrade o) {
if (getAverage() == o.getAverage()) {
return 0;
}
else if (getAverage() > o.getAverage()) {
return 1;
}
else
return -1;
}
}
// Skip & Get next question Submit answer
class Professor {
private String name;
public Professor(String name) {
this.name = name;
}
public String getName() {
return name;
}
public boolean equals(Object o) {
if (getName().equals(o))
return true;
else
return false;
}
}
class Course {
private String department;
private int courseNumber;
private char special;
private String section;
public Course(String department, int courseNumber, char special, String section) {
this.department = department;
this.courseNumber = courseNumber;
this.special = special;
this.section = section;
}
public String getDepartment() {
return department;
}
public String getCourse() {
return (department + courseNumber + special);
}
public String getSection() {
if (!section.equals("-1"))
return ("0" + section);
else
return section;
}
public boolean equals(Object o) {
String w = o.toString();
if (getCourse().equals(w))
return true;
else
return false;
}
o float getProfessorAverage (Professor p), which returns the average GPA a professor gave Note that you should not calculate the average with a simple mean between the courses a professor teaches. The average should be weighted based on how many students took a course a professoir taught. For example, suppose a professor teaches two courses: course A with 20 students and course B with 10 students. The average GPA in course A is a 3.53 and in course B is a 3.08. The average GPA should be calculated as: (3.53 * 20) (3.08 10) 20 + 10 Think about how you can calculate this using a for loop. This method will return the average GPA the professor gave, which should be a float. If the given rofessor did not teach any courses, or only gave "Other" grades, return -1 o float getCourseAverage (Course course, boolean sectionOnly), which returns the average GPA of a course It is possible that multiple CourseGrade objects exist for a single course (i.e., multiple sections of a course -CMSC131 might have sections 0101 and 0102, and these will be separate CourseGrade objects). If sectionOnly is false, the average should be weighted based on how many students took the course across all sections, again ignoring grades of "Other". In this case, the section of the given course should not be used. In other words, if sectionOnly is false, calculate the average GPA of a course across all sections If sectionOnly is true, you should compute the average only for the section of the course given as a parameter This method will return the average GPA, which should be a float. If no student took the course, or if the only grades are "Other", return -1. o float getDepartmentAverage (String department), which returns the average GPA of the courses offered by the department. The average should be weighted based on how many students took the courses, as explained above, again ignoring grades of "Other". This method will return the average GPA of all courses in the given department, which should be a float. If no students received a grade in the department, or if the only grades are "Other", return -1. o float getProfessorAverage (Professor p), which returns the average GPA a professor gave Note that you should not calculate the average with a simple mean between the courses a professor teaches. The average should be weighted based on how many students took a course a professoir taught. For example, suppose a professor teaches two courses: course A with 20 students and course B with 10 students. The average GPA in course A is a 3.53 and in course B is a 3.08. The average GPA should be calculated as: (3.53 * 20) (3.08 10) 20 + 10 Think about how you can calculate this using a for loop. This method will return the average GPA the professor gave, which should be a float. If the given rofessor did not teach any courses, or only gave "Other" grades, return -1 o float getCourseAverage (Course course, boolean sectionOnly), which returns the average GPA of a course It is possible that multiple CourseGrade objects exist for a single course (i.e., multiple sections of a course -CMSC131 might have sections 0101 and 0102, and these will be separate CourseGrade objects). If sectionOnly is false, the average should be weighted based on how many students took the course across all sections, again ignoring grades of "Other". In this case, the section of the given course should not be used. In other words, if sectionOnly is false, calculate the average GPA of a course across all sections If sectionOnly is true, you should compute the average only for the section of the course given as a parameter This method will return the average GPA, which should be a float. If no student took the course, or if the only grades are "Other", return -1. o float getDepartmentAverage (String department), which returns the average GPA of the courses offered by the department. The average should be weighted based on how many students took the courses, as explained above, again ignoring grades of "Other". This method will return the average GPA of all courses in the given department, which should be a float. If no students received a grade in the department, or if the only grades are "Other", return -1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
