Computer Science Courses
Related sites
HW 4 |
Construct and test a Student class which stores the followingdata:
Write accessor/mutator (get()/set(x)
) methods for each field.
Override toString() method of the Student classto return "Name, Department, Year Commenced" information on theStudent object
Write overloaded constructors so that a student can be constructed in several different way:
Think how to minimise code repetition in these constructors by calling other constructor using theStudent() Student(name) Student(name, address) Student(name, address, department)
this(…)
syntax. Write a test class, StudentTest, to test this class by creating an array of three students. Print out the students data as it's doneby toString() method (actually you don't need to call this method; just put your object into a print statement and it gets called automatically!).
Add a student ID field, studentID, and another staticfield nextID for counting students. Write a private method toincrement the last value. Modify every constructorto set the value of studentID to the currentvalue of nextID, and increment nextID each time a student object isconstructed. Initialise the nextID to a static constant,STUDENT_ID_BASE=901000 (static variables are initialisedprior to the first constructor call). Finally, modifytoString() method to print the student information includingthe student id.
Optional.
ArrayList<Student>
instead of array of Student
s.Why the new version is better?You will get up to two marks, if you present a solution to the Homeworkexercise during the next week lab.
HW 4 |
Updated: Sun 12 Jun 2016 17:27:37 AEST • Responsible Officer: JavaScript must be enabled to display this email address. • Page Contact:
+61 2 6125 5111
The Australian National University, Canberra
CRICOS Provider : 00120C ABN : 52 234 063 906