public class Student { //Instance Fields private String name; //a reference to a String private StringBuffer nickname; //a reference to a StringBuffer public String uid; //a reference to a String //NOTE: We made this public to demonstrate why that's not considered good style. private float semesterScore; //a primitive //Static Fields - these need to be initialized here private static int currentCount = 0; private static int overallCount = 0; private static final String DEFAULT_NICKNAME = "NoNick"; private static final int DEFAULT_UID = 0; //Constructors public Student(String nameIn, String nickIn, int uidIn) { setName(nameIn); setNickname(nickIn); setUID(uidIn); setScore(0.0F); currentCount++; overallCount++; } public Student(String nameIn, int identIn) { this(nameIn, DEFAULT_NICKNAME, identIn); } public Student(String nameIn) { this(nameIn, DEFAULT_NICKNAME, DEFAULT_UID); } public Student() { this("Anonymous"+currentCount, DEFAULT_NICKNAME, DEFAULT_UID); } //Copy Constructor public Student(Student existingStudent) { this( existingStudent.getName(), existingStudent.getNickname(), existingStudent.getUID() ); setScore(existingStudent.getScore()); } //So-called "destructor" but not like in other languages protected void finalize() throws Throwable { //NOTE: This is only called if/when garbage collection takes place // to clean up no longer used memory. currentCount--; super.finalize(); //We'll talk more about this line later... } //Getters and Setters public void setName(String nameIn){ name = nameIn; } public String getName() { return name; } public void setNickname(String nickIn) { nickname = new StringBuffer(nickIn); } public String getNickname() { return nickname.toString(); } public void appendNickname(String suffix) { nickname.append(suffix); } public void setUID(int uidIn){ uid = convertIntToString(uidIn); } public int getUID() { return convertUIDToInt(uid); } public void setScore(float scoreIn) { semesterScore = scoreIn; } public float getScore() { return semesterScore; } //Static Helper Methods that don't use any class data private static String convertIntToString(int inVal) { String retval; if ((inVal > 0) && (inVal < 1000000000)) { String convertedNumber = Integer.toString(inVal); int leadingZeroCount = 9 - convertedNumber.length(); String leadingZeroHolder = ""; for (int i=0; i