Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Class from Assignment 3 that needs updating is at the bottom. Update your pr

ID: 3532805 • Letter: T

Question

The Class from Assignment 3 that needs updating is at the bottom.

Update your program that tracks your progress as a student in this class. It is recommended that you copy the code from Assignment 3 to begin this assignment.  

Update the Student class which should have six private instance variables and after the following changes.  

The first two will remain the same. They are as follows:

//same as before
private String name;
private String id;

Then you should remove the following private instance variables:

//remove these
private int quizScores;
private int assignmentScores;

Add these two variables:

//new arrays
private int[] quizArray;
private int[] assignmentArray;

These two arrays will hold all quiz and assignment grades.  

The class will have two new private instance variables:

private int numberOfQuizzes;
private int numberOfAssignments;

The class should have the same public methods as Assignment 4, but should change the following constructor:  

//Postcondition: creates a Student object which assigns these values to the instance variables
//name = "";
//id = "";
//quizArray = new int[7];
//assignmentArray = new int[7];
//numberOfQuizzes = 0;
//numberOfAssignments = 0;
This constructor should also loop through both arrays and set every value to -1.  
public Student()

and the following method definitions will change, but not their signatures:

//Precondition: newQuiz >= 0
//Postcondition: stores the value of the newQuiz
This method will need to increment numberOfQuizzes by 1 and place the quiz into the quizArray
public void addQuiz(int newQuiz)

//Postcondition: returns the sum of the student's quiz scores
This method will loop through the quizArray up to and including numberOfQuizzes and add all the quiz scores and return the sum
public int getQuizScores()

//Precondition: newAssignment >=0
//Postcondition: stores the value of the newAssignment
This method will need to increment numberOfAssignments by 1 and place the assignment into the assignmentArray
public void addAssignment(int newAssignment)

//Postcondition: returns the sum of the student's assignment scores
This method will loop through the assignmentArray up to and including numberOfAssignments
and add all the assignment scores and return the sum
public int getAssignmentScores()
  

//Precondition: newQuiz1 >= 0 and newQuiz2 >= 0
//Postcondition: stores the values of newQuiz1 and newQuiz2
This method will need to increment numberOfQuizzes by 2 and place the two quizzes into the quizArray
**Hint: the easiest way to accomplish this method is to make two calls to the other addQuiz method**
public void addQuiz(int newQuiz1, int newQuiz2)


//Precondition: newAssignment1 >=0 and newAssignment2 >= 0
//Postcondition: stores the values of newAssignment1 and newAssignment2
This method will need to increment numberOfAssignments by 2 and place the two assignments into the assignmentArray
**Hint the easiest way to accomplish this method is to make two calls to the other addAssignment method**
public void addAssignment(int newAssignment1, int newAssignment2)


CLASS:

public class Student {

private String name;


private String id;


private int quizScores;


private int assignmentScores;


public Student() {

super();

}


public Student(String name, String id, int quizScores, int assignmentScores) {

super();

this.name = name;

this.id = id;

this.quizScores = quizScores;

this.assignmentScores = assignmentScores;

}


public String getName() {

return name;

}


public void setName(String name) {

this.name = name;

}


public String getId() {

return id;

}


public void setId(String id) {

this.id = id;

}


public int getQuizScores() {

return quizScores;

}


public void setQuizScores(int quizScores) {

this.quizScores = quizScores;

}


public int getAssignmentScores() {

return assignmentScores;

}


public void setAssignmentScores(int assignmentScores) {

this.assignmentScores = assignmentScores;

}


public void addQuiz(int newQuiz)

{

if(newQuiz >= 0)

{

quizScores += newQuiz;



}

}

public void addAssignment(int newAssignment)

{

if(newAssignment >= 0 )

{

this.assignmentScores += newAssignment;

}

}


public void addQuiz(int newQuiz1, int newQuiz2)

{

if(newQuiz1 >= 0 && newQuiz2 >=0 )

{

quizScores += (newQuiz1 + newQuiz2);

}


}

public void addAssignment(int newAssignment1, int newAssignment2)

{

if(newAssignment1 >=0 && newAssignment2 >=0)

{

assignmentScores += (newAssignment1+newAssignment2);

}

}

}

Explanation / Answer

public class Student {

private String name;


private String id;

private int[] quizArray;

private int[] assignmentArray;

private int numberOfQuizzes;

private int numberOfAssignments;


public Student() {

super();

this.name = "";

this.id = "";

this.quizArray=new int[7];

this.assignmentArray=new int[7];

this.numberOfQuizzes=0;

this.numberOfAssignments=0;

for(int i=0;i<quizArray.length;i++)

{

quizArray[i]=-1;

}

for(int i=0;i<assignmentArray.length;i++)

{

assignmentArray[i]=-1;

}

}


public String getName() {

return name;

}


public void setName(String name) {

this.name = name;

}


public String getId() {

return id;

}


public void setId(String id) {

this.id = id;

}


public void addQuiz(int newQuiz)

{

if(newQuiz >= 0)

{

quizArray[numberOfQuizzes]=newQuiz;

numberOfQuizzes++;

}

}

public void addAssignment(int newAssignment)

{

if(newAssignment >= 0 )

{

assignmentArray[numberOfAssignments]=newAssignment;

numberOfAssignments++;

}

}


public int getAssignmentScores()

{

int sum=0;

for(int i=0;i<=numberOfAssignments;i++)

{

sum+=assignmentArray[i];

}

return sum;

}

public int getQuizScores()

{

int sum=0;

for(int i=0;i<=numberOfQuizzes;i++)

{

sum+=quizArray[i];

}

return sum;

}

public void addQuiz(int newQuiz1, int newQuiz2)

{

if(newQuiz1 >= 0 && newQuiz2 >=0 )

{

addQuiz(newQuiz1);

addQuiz(newQuiz2);

}


}

public void addAssignment(int newAssignment1, int newAssignment2)

{

if(newAssignment1 >=0 && newAssignment2 >=0)

{

addAssignment(newAssignment1);

addAssignment(newAssignment2);

}

}

}


Here is StudentDemo


public class StudentDemo

{

public static void main(String[] args)

{

Student s1=new Student();

s1.setName("Mik Jor");

s1.setId("123123");

s1.addQuiz(50,36);

s1.addAssignment(100);

System.out.println("The Student details are:");

System.out.println("Name: "+s1.getName());

System.out.println("ID: "+s1.getId());

System.out.println("Quiz Score: "+s1.getQuizScores());

System.out.println("Assignment Score: "+s1.getAssignmentScores());

}

}