Question: Imagine there is a Java Class, Course, which contains an attribute, students, which is an array of Student types. The Student class contains an attribute,
Imagine there is a Java Class, Course, which contains an attribute, students, which is an array of Student types. The Student class contains an attribute, quizScores, which is an array of integers representing the quiz scores of the student. Here is the partial implementation of each class:
public class Course {
private Student [] students;
private String courseName;
public Course(String n) {courseName = n;}
public void setStudents(Student[] stus) { students = stus;}
.... // other methods
}
public class Student {
private String name;
private int[] quizScores;
public Student(String n) { name = n;}
public void setQuizScores(int[] scores) { quizScores = scores; }
.. // other methods
The main program (in part looks like this)
public static void main(String[] args) {
int [] s1quizzes = {100, 95, 83, 98};
int[] s2quizzes = {80, 83, 82, 88};
int [] s3 quizzes = {75, 80, 90, 82};
Student s1 = new Student ("Maria");
s1.setQuizScores(s1quizzes);
Student s2 = new Student("Alvin");
s2.setQuizScores (s2quizzes);
Student s3 = new Student("Pat")
s3.setQuizScores(s3quizzes);
Student[] roster = (s1, s2, s3);
Course x = new Course("x");
x.setStudents(roster);
s1quizzes[0] = 0;
s3.setName("Kavya");
System.out.println(x):
}
when the results are printed
Course X:
Maria: 100, 95, 83, 98
Alvin: 80, 83, 82, 88
Kavya: 75, 80, 90, 82
Why is the change to Maria's first quiz score (from 100 to 0) in array s1quizzes not reflected in the final output yet the student name change (from "Pat" to "Kavya") is reflected in the output?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
