I'm writing a StudentInfo class that implements the Student interface. one common thing about these errors is that each of the methods i have in StudentInfo class cannot implement corresponding method in the Student interface. can someone explain that error for me and show me how to use the List class in my case. Thanks a lot!
This is the Student interface
/**
* A simple interface to allow access to student
* properties from a class data file.
*/
public interface Student {
// Read-only properties
List<Double> getGrades();
String getFirstName();
String getMiddleInitial();
String getLastName();
}
This is the StudentInfo class i am wrting:
import java.util.List;
/**StudentInfo.java modeling a student's infomation
*A student's info includes first name, middle initial, last name and grades
*/
public class StudentInfo implements Student {
protected String myFirstName, myMiddleInitial, myLastName;
protected List<Double> myGrades = new List<Double>();
StudentInfo(String firstName, String middleInitial, String lastName) {
myFirstName = firstName;
myMiddleInitial = middleInitial;
myLastName = lastName;
}
// Read-only properties
List<Double> getGrades() { return myGrades; }
String getFirstName() { return myFirstName; }
String getMiddleInitial() { return myMiddleInitial; }
String getLastName() { return myLastName; }
}
Here are the errors:
StudentInfo.java:19: getLastName() in StudentInfo cannot implement getLastName() in Student; attempting to assign weaker access privileges; was public
String getLastName() { return myLastName; }
^
StudentInfo.java:18: getMiddleInitial() in StudentInfo cannot implement getMiddleInitial() in Student; attempting to assign weaker access privileges; was public
String getMiddleInitial() { return myMiddleInitial; }
^
StudentInfo.java:17: getFirstName() in StudentInfo cannot implement getFirstName() in Student; attempting to assign weaker access privileges; was public
String getFirstName() { return myFirstName; }
^
StudentInfo.java:16: getGrades() in StudentInfo cannot implement getGrades() in Student; attempting to assign weaker access privileges; was public
List<Double> getGrades() { return myGrades; }
^
StudentInfo.java:9: java.util.List is abstract; cannot be instantiated
protected List<Double> myGrades = new List<Double>();