This is what I came up with. If you need me to explain anything feel free to message me.
Code:
public class StudentClient {
public static void main(String[] args) {
Student mark = new Student("Mark", 555555555, 3.6);
System.out.println(mark.toString());
Student leslie = new Student();
leslie.equals(mark);
leslie.setName("Leslie");
System.out.println(leslie.toString());
}
}
Code:
public class Student {
private String name;
private int socialSecurityNumber;
private double gpa; // grade point average
private static final String DEFAULT_NAME = "Unregistered";
private static final int DEFAULT_SOCIAL_SECURITY_NUMBER = 111111111;
private static final int HIGHEST_SOCIAL_SECURITY_NUMBER = 999999999;
private static final double LOWEST_GPA = 0.0;
private static final double HIGHEST_GPA = 4.0;
public String toString() {
String information = "Name: " + name;
information += "\n" + "Social Security Number: " + socialSecurityNumber;
information += "\n" + "G.P.A: " + gpa;
return information;
}
public void equals(Student student) {
this.name = student.getName();
this.socialSecurityNumber = student.getSocialSecurityNumber();
this.gpa = student.getGpa();
}
// ================================== CONSTRUCTORS =========================================== //
public Student() {
this(DEFAULT_NAME, DEFAULT_SOCIAL_SECURITY_NUMBER, LOWEST_GPA);
}
public Student(String name) {
this(name, DEFAULT_SOCIAL_SECURITY_NUMBER, LOWEST_GPA);
}
public Student(int socialSecurityNumber) {
this(DEFAULT_NAME, socialSecurityNumber, LOWEST_GPA);
}
public Student(double gpa) {
this(DEFAULT_NAME, DEFAULT_SOCIAL_SECURITY_NUMBER, gpa);
}
public Student(String name, int socialSecurityNumber) {
this(name, socialSecurityNumber, LOWEST_GPA);
}
public Student(String name, double gpa) {
this(name, DEFAULT_SOCIAL_SECURITY_NUMBER, gpa);
}
public Student(int socialSecurityNumber, double gpa) {
this(DEFAULT_NAME, socialSecurityNumber, gpa);
}
public Student(String name, int socialSecurityNumber, double gpa) {
// check to see if blank string was passed as the name
// if it was then set name to default value otherwise set this.name = to string passed
if (name.equals("")) {
this.name = DEFAULT_NAME;
}else {
this.name = name;
}
// check that social is between 0 and 999999999
// if not set it equal to default value
if (socialSecurityNumber >= DEFAULT_SOCIAL_SECURITY_NUMBER && socialSecurityNumber <= HIGHEST_SOCIAL_SECURITY_NUMBER) {
this.socialSecurityNumber = socialSecurityNumber;
} else {
this.socialSecurityNumber = DEFAULT_SOCIAL_SECURITY_NUMBER;
}
// ensure that the gpa passed to the method is between 0.0 and 4.0 inclusive
// else set it equal to lowest value
if (gpa >= LOWEST_GPA && gpa <= HIGHEST_GPA) {
this.gpa = gpa;
} else {
this.gpa = LOWEST_GPA;
}
}
// ============================ Getter and Setters ===================================== //
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public int getSocialSecurityNumber() {
return this.socialSecurityNumber;
}
public void setSocialSecurityNumber(int socialSecurityNumber) {
this.socialSecurityNumber = socialSecurityNumber;
}
public double getGpa() {
return this.gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
}
- - - Updated - - -
Here was the output from the code above:
Name: Mark
Social Security Number: 555555555
G.P.A: 3.6
Name: Leslie
Social Security Number: 555555555
G.P.A: 3.6
Process finished with exit code 0