Modify the Student class to store a student ID as a String instance variable. The student id is not known when the class is created, but is added later and can be changed. Define the instance variable and initiatlize it to the empty string. Then define the two methods to support encapsulation: the getID() and setID().
Student class:
public class Student
{
// Declaration of instance variables
private String name;
private String major;
private int yearEnrolled;
// Constructor
public Student(String n, int y) {
name = n;
major = “undeclared”;
yearEnrolled = y;
}
public void setMajor(String m) { major = m; }
public String getMajor() { return major; }
public int getYear() { return yearEnrolled; }
public String getName() { return name; }
// Define instance variable
String …
// Define the accessor
public String getID() {
…
}
// Define the mutator (set)
public void setID(…) {
…
}
}
To start with:
// Define instance variable
String //…
// Define the accessor
public String getID() {
// …
}
// Define the mutator (set)
public void setID( /* … */ ) {
// …
}