Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439

Computer Science Courses

Related sites

Introductory Programming In Java

HW 4

Homework 4

Defining your own class and testing it

The problem

  1. Construct and test a Student class which stores the followingdata:

    • Name
    • Address
    • Degree name
    • Department
    • Year Commenced
  2. Write accessor/mutator (get()/set(x)) methods for each field.

  3. Override toString() method of the Student classto return "Name, Department, Year Commenced" information on theStudent object

  4. Write overloaded constructors so that a student can be constructed in several different way:

    Student() Student(name) Student(name, address) Student(name, address, department)
    Think how to minimise code repetition in these constructors by calling other constructor using the this(…) syntax.

  5. 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!).

  6. 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.

  7. Optional.

    • Modify the above program to use ArrayList<Student> instead of array of Students.Why the new version is better?
    • Modify the Student class so that the student ID is assignedbased on the year of commencement (to fit the ANU format where the firsttwo digits are the last two digits of the commencement year, and the remaining five digits represent a unique number incremented by every new studentenrolled on the same year; for example, the two IDs —9207147 and 0207147 are both count 7,147th student enrolled correspondinglyon 1992 and on 2002. You may assume that there was no enrolled studentsbefore the University was founded, in 1947).

Assessment

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