Question
Instruction There are four classes you must implement. All of the instance variables you need to complete the project are included in the starter ?les.
Instruction There are four classes you must implement. All of the instance variables you need to complete the project are included in the starter ?les. If you need any other instance variables, declare those as private variables. The requirements for each class are described below. 1. The Professor class represents a professor. It must have the following: Instance variables:
String name, representing a Professors name Constructors:
A constructor that takes a name and sets the instance variable to it Methods:
String getName() that returns the name of the Professor
boolean equals(Object o) that returns true if two Professors have the same name and false otherwise 2. The Course class represents a course. It must have the following: Instance variables:
String department, representing a Courses department
int courseNumber, representing a Courses course number
char special, representing a Courses special number. For example, for CMSC389A, the A would be stored in special
String section, representing a Courses section Constructors:
A constructor that takes a department, courseNumber, special, and section, and sets each instance variable to the respective parameter. See the instance variable description above for the types. If the section parameter has 3 characters, add a 0 before it. This is because in the grade data ?le, section 0101 is written as 101. Methods:
String getDepartment() that returns the Courses department
String getCourse() that returns the full name of the Course. For example, a course with department CMSC, courseNumber 131, and s \0 (explained below) would return CMSC131. Note that (1) there are no spaces between department, course and special and (2) the \0 character should always be added to the return String, even if it is not displayed. String getSection() that returns the Courses section
boolean equals(Object o) that returns true if two Courses have the same name (as de?ned in getCourse()) and false otherwise. Note that two Courses are equal even if they have di?erent sections. 3. The CourseGrade class connects a Professor and a Course with grades. It must have the following: Instance variables:
Professor professor, representing the CourseGrades professor
Course course, representing the CourseGrades course
Map
Professor getProfessor() that returns the CourseGrades professor
Course getCourse() that returns the CourseGrades course
Map
void updateGrade(String grade, int numStudents) that sets grades for the key grade to numStudents. It should overwrite any previously stored grade.
float getAverage() that returns the average GPA for CourseGrade. A grade can be converted to a GPA using this table (found here): A+ A A- B+ B B- C+ C C- D+ D D- F W Other 4.0 4.0 3.7 3.3 3.0 2.7 2.3 2.0 1.7 1.3 1.0 0.7 0.0 0.0 Ignore Note that this does not follow the way UMD calculates grades exactly. For example, this project counts a W as a 0, whereas UMD does not include Ws in GPA calculations. Other grades are grades which were not reported for some reason. They should be ignored. For example, a course with 3 students who received an A-, 1 who received a C, 1 who received a W, and 1 who received an Other will have an average GPA of 2.62: (3?3.7) + (1?2.0) + (1?0.0) (3 + 1 + 1) = 2.62 We divide by 5, not 6, because we do not include the Other grade in the average calculation. Note that you do not need to round; just return what you calculated.
int getNumGrade(String grade) that returns the number of students who received the given grade. Using the example above, calling getNumGrade("A-") should return 3. You can assume that before this method is called, updateGrade will have been called for each grade.
int getNumStudents() that returns the total number of students who received a grade (including students who received a grade of Other).
int compareTo(CourseGrade cg). Notice that the CourseGrade class implements Comparable, an interface in Java (https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html). This interface gives classes a way to compare objects using the compareTo method. This method should return 0 if the current CourseGrade object has the same average GPA as the CourseGrade object given as the parameter, 1 if the current CourseGrades average GPA is greater than the parameters average GPA, and -1 otherwise. Read this to see how to check if floats are roughly equal. Use 0.000001 as the epsilon. 4. The Analyze class contains methods to analyze the grade data. It must have the following: Instance variables:
List
A default constructor that initializes courseGrades to a new, empty ArrayList Methods:
void readData (String fileName) Note that this method has already been implemented. Do not modify it. This method reads the passed grades ?le, which you can assume exists and is a Comma-Separated Values (CSV) ?le. This means the data is separated by commas. The ?rst row is a header row that shows how the data is ordered. Here are two rows from the ?le (the header row, and row #1925): 3 Course,Section,Professor,Total,A+,A,A-,B+,B,B-,C+,C,C-,D+,D,D-,Fs,Withdraw,Other CMSC250,401,Roger D. Eastman,33,1,1,4,6,5,2,1,6,3,0,0,1,1,2,0 You can match these rows up. CMSC250 is the Course, 401 is the Section, Roger D. Eastman is the Professor, a total of 33 students received a grade, 1 student received an A+, and so on. Observe that the method reads through the ?le line-by-line and adds CourseGrades to gradesList after creating a Course and a Professor object for each row. It also sets the grades of a CourseGrade object from the grade data given in the row. Note that the number of students who received an Other grade is also added to a CourseGrade object. If a course does not have a special character, the null character is assigned to special. This is done by setting, for example, char special = '\0' or char special = 0. Once this method is completely executed, courseGrades will have all of the data from fileName. 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 professor 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 = 3.38 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 professor did not teach any courses, or only gave Other grades, return -1.
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.
float getDepartmentAverage (String department), which returns the average GPA of the courses o?ered 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.
List
List
-----------------------------------------------------------------------
public Analyze () {
courseGrades=null;
}
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();
}
public float getProfessorAverage (Professor p) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public float getCourseAverage (Course c, boolean sectionOnly) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public float getDepartmentAverage (String department) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public List
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public List
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
}
---------------------------------------------------------------------
mport java.util.HashMap;
public class Course {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public Course (String department, int courseNumber, char special, String section) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public String getDepartment() {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public String getCourse () {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public String getSection() {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public boolean equals (Object o) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
---------------------------------------
ublic class CourseGrade implements Comparable private Professor professor; private Course course; private Map public CourseGrade (Professor professor, Course course) { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } public Professor getProfessor() { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } public Course getCourse() { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } public Map throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } public void updateGrade (String grade, int numStudents) { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } public float getAverage () { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } public int getNumGrade (String grade) { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } public int getNumStudents() { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } @Override public int compareTo(CourseGrade o) { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } } |
------------------------------------
public class Professor {
public Professor (String name) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public String getName () {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
public boolean equals (Object o) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started