I have an assignment to make a student class with setter and getter methods followed by a course class where we make an array of student objects that we use to test the methods from that student class. I am clearly doing something wrong though.
class Course{
static Student[] Roll = new Student[10];
public static void main(String[] args) {
Roll[0] = new Student("Burris","Adam", 20221483, "CompSci", 4.0, 2, 8);
Roll[1] = new Student("Blanton","Emily", 21221484, "Finance",3.0, 2, 6);
Student Student3 = new Student("Allred","Adam", 22221485, "Kinesiology",3.8, 20, 76);
Student Student4 = new Student("Johnston", "Josh", 23221486, "CompSci", 3.0, 20, 60);
Student Student5 = new Student("Perryman", "Noah", 24221487, "BCIS", 2.79, 43, 120);
System.out.println(Student3.getName());
Student3.setFullName("Emily Burris");
System.out.println(Student3.getName());
System.out.println(Roll[1].getName());
}
}
Result:
Noah Perryman
Emily Burris
Emily Burris
I'm not understanding why the getName() is only pulling the last reference to names. First it is the bottom student then it is my setFullName method.
Student class:
class Student{
private static String fullName;
private static int studentID;
private static String major;
private static double GPA;
private static int classesTaken;
private static double scores;
public Student (String lastName, String firstName, int studentID, String major,
double GPA, int classesTaken, double scores) {
Student.fullName = firstName + " "+ lastName;
this.studentID = studentID;
this.major = major;
this.GPA = GPA;
this.classesTaken = classesTaken;
this.scores = scores;
}
public String getName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public int getStudentID() {
return studentID;
}
public void setStudentID(int studentID) {
this.studentID = studentID;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public void completed(double newScore) {
classesTaken = classesTaken + 1;
scores = scores + newScore;
GPA = scores / classesTaken;
}
public double getGPA() {
return GPA;
}
public int getClassesTaken() {
return classesTaken;
}
public double getScores() {
return scores;
}
}