Computer science and IT assignments Undergraduate

Students

After completing this assignment, you should know how to
write a class with multiple constructors
write the toString and equals methods
throw an exception
Read the instructions and coding standards before uploading your code.
Your code should not contain compiler errors and it must run with my test file to receive
credit.
Copy your output into Canvas when you upload your assignment.
Very important
Changing an array value in the main method should not change an array value in
a Student object
Changing an array value in a Student object should not change an array value
the main method
Changing an array value in a Student object should not change an array value in
another Student object

1. Write a public class called Student with the following features
o private instance variables
String firstName
String lastName
int[] grades
int age
o constructor with the following header
public Student(String firstName, String lastName, int[] grades, int age)
use the input parameters to initialize the instance variables.
o constructor with the following header
public Student(Student student)
use the input parameter to initialize the instance variables. This
constructor creates a copy of the input parameter.
o mutator and accessor methods for each instance variable
o A method with the header
public String toString()
this method returns a String that contains the firstName, lastName, age,
highest grade, and average grade. The average grade should contain
exactly two decimal places of accuracy. You must use the
getHighestGrade and getAverageGrade methods to find the highest grade
and average grade. The output should be in a user-friendly format.
Hint: Use String.format; see Book.java an example.
o A method with the header
public boolean equals(Object o)
this method returns true if the parameter o is a Student object with the
same name and age as the current object. Otherwise, the method returns
false. (The Book class contains an example of how to write an equals
method.) Do not compare grades in the equals method.

o A method with the header
public int getHighestGrade()
this method returns the greatest value stored in grades.
o A method with the header
public double getAverageGrade()
this method returns the average grade. If there are more than four
grades then drop the lowest score before computing the average.
o A method with the header
public void incrementGrade(int i, int value)
throws an IllegalArgumentException if value < 0 or value> 100.
Otherwise, add value to grade[i]. If the revised score is greater than
100 set the grade to 100.
Very Important
To avoid side-effect your code should not contain statements similar to
this.grades = grades;
return grades;
In the constructors and mutator method
allocate memory for this.grades; the length should be identical
to the length of the parameter grades.
copy the data in the parameter grades to this.grades.
In the accessor method
declare a local int array; the length should be identical to the
length of this.grades.
copy the data in this.grades to the local variable
return the local variable

Coding Instructions
1. Do not use any Java classes or methods that trivialize the problem.
2. Remove all irrelevant statements. For instance, do not declare a variable that is
not used in your code.
3. Only declare the instance variables described in the problem description.
4. Each instance variable should be declared on a separate line.
5. You can write additional methods but they should be declared as private.
6. Use consistent notation to format your code. Indent 4-spaces.
7. Variables and methods should start with a lower-case character. Each
abbreviation or word that appears in the middle of the identifier starts with an
uppercase character.
8. Use System.arraycopy instead of manual copy.
9. Do not use break statements.
10.Do not change the value of a counter variable to terminate a loop:
Example:
for (int i = 0; i < arr.length; i++){
if (arr[i] < 0)
i = arr.length;
}
11.Loops should not perform any irrelevant iterations.
12.Each method should have at most one return statement.
13.Do not use a return statement in a void method.
14.Do not use a while loop when an if statement is appropriate for the code
segment. (In other words, do not write a while that is guaranteed to iterate at
most one time.)
15. Do not double space. Separate code segments with a most one blank line.
16.Do not compare a boolean variable to true or false.
17.A block comment near the top of the Java file with the following information
/*
Author: Your name and an acknowledgement of any person who assisted you in
this project.
Date: The date you completed the assignment.
Purpose: A description of the class.
*/

18. Write a block comment above each method and constructor with the following
information:
/*
Purpose: A meaningful description of the method/constructor.
Parameters: Describe the purpose of each parameter
Return: A description of the return value.
*/