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

The school would like to add a unique identifier to every student as each record

ID: 3903402 • Letter: T

Question

The school would like to add a unique identifier to every student as each record object is created. Modify the class properties and constructor to achieve this. Show the result below:

public class Student {

    private String firstName;     // first name

    private String lastName;      // last name

    private String email;     // email address

    private int catalogYear;   //catalog year for student entrollment

  // construct a new student with given fields

    public Student(String first, String last, String email, int section) {

        this.first   = first;

        this.last    = last;

        this.email   = email;

        this.section = section;

    }

Explanation / Answer

public class Student { private static int count = 0; private static int id;//unique id private String firstName; // first name private String lastName; // last name private String email; // email address private int catalogYear; //catalog year for student entrollment public Student() { } public Student(String firstName, String lastName, String email, int catalogYear) { this.id = count; this.firstName = firstName; this.lastName = lastName; this.email = email; this.catalogYear = catalogYear; count++; } public static int getId() { return id; } public static void setId(int id) { Student.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public int getCatalogYear() { return catalogYear; } public void setCatalogYear(int catalogYear) { this.catalogYear = catalogYear; } }