This lab requires you to work on your own to create an inher
This lab requires you to work on your own to create an inheritance hierarchy.
A student has first name, last name, email address, BCIT id, collection of courses (course name and grade – use HashMap<String, Double>). This class has a method to put a new course into the student\'s course collection and a method that calculates and returns the student\'s average grade. (Be sure not to divide by zero.)
An instructor has first name, last name, email address, BCIT id, hourly wage.
Provide both default and non-default constructors at all levels of the hierarchy. All attributes must have appropriate “get” and “set” methods.
Provide a Database class with an ArrayList that holds both Student and Instructor references. This class has a method to add someone to the database, and a method that displays the names and email addresses of everyone in the database.
Solution
import java.util.HashMap;
import java.util.Set;
public class Student extends Member
{
// instance variables of class Student
private HashMap<String, Double> courses;
public Student()
{
super();
courses = new HashMap<String, Double>();
}
public Student(String firstName, String lastName, String emailAddress, String bcitId)
{
super(firstName, lastName, emailAddress, bcitId);
courses = new HashMap<String, Double>();
}
public void addCourse(String course, Double grade)
{
if(!courses.isEmpty()) {
courses.put(course, grade);
}
}
public Double getAverageGrade()
{
Double averageGrade = 0.0;
int counter = 0;
if(!courses.isEmpty())
{
for(Double grade : courses.getValues()){
averageGrade += grade
counter++;
}
}
else
{
return -1;
}
return (averageGrade /= counter);
}
return (averageGrade / counter);
}
}

