Question: 2a) Draw a UML diagram for Course.java 2b) complete Course.java class implementation and test it (5 points). Cut following code and replace it with your
2a) Draw a UML diagram for Course.java
2b)
complete Course.java class implementation and test it (5 points).
Cut following code and replace it with your completed implementation.
//Course.java
import java.util.ArrayList;
public class Course {
private String courseName;
private ArrayList
private int numberOfStudents = 0;
private ArrayList
public Course(String courseName) {
this.courseName = courseName;
} public void addStudent(String student, String grade) {
students.add(student);
//Todo: add the grade to grades numberOfStudents++;
}
//to do: needs correct type public _____ getStudents() { return students;
}
//to do: needs correct type public _____ getGrades() { return grades;
} public int getNumberOfStudents() { return numberOfStudents;
} public String getCourseName() { return courseName;
}
//Todo: remove the student and the student's grade public void dropStudent(String student) {
/* TODO: find the index, so that students.get(index)==student then you can call students.remove(index) to remove the student from students. Similarly to remove the students's grade
*/
}
public int[] countGrades(){ //count: A+, A, A-, B+, B, B-, ..., D+, D, D-, F final String[] letter={"A+","A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F"}; int[] counts = new int[13];
//Todo: go over grades, compare each item with letter
//update counts return counts;
}
public static void main(String[] args) { Course course1 = new Course("Data Structures"); Course course2 = new Course("Database Systems");
course1.addStudent("Peter Jones", "A"); course1.addStudent("Brian Smith", "B"); course1.addStudent("Anne Kennedy", "B");
//add 5 more students
System.out.println("Number of students in course1: "
+ course1.getNumberOfStudents());
//Todo: add proper type, (String[] students is not correct)
_______ students = course1.getStudents();
//Todo: add proper type, (String[] grades is not correct)
_______ grades = course1.getgrades();
for (int i = 0; i < course1.getNumberOfStudents(); i++) //to do: print the Is students
System.out.print(students._____ + ": " + grades);
System.out.println();
//To do: Add code to print number of students got A+, A, A-
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
