Fall 2013
Solutions to Homework #5
Assigned: October 19; Due: October 24
H5.1
Write a Java application with a simple class inheritance hierarchy. As shown in the UML diagram below, it should consist of three classes. The Student class, representing a student’s personal and course registration information for a given semester, which will be the superclass. The two subclasses inheriting from the Student class are the FullTimeStudent class, representing a full-time student’s personal and registration info, and the PartTimeStudent class, representing a part-time student.
The rules for valid registration are as follows. All students (both full-time and part-time) must register for at least one course and can register for at most four courses. In addition, full-time students must register for at least three courses to be able to maintain their full-time status, while part-time students can register for at most two courses.
The Student class should have five fields: two static constants, one representing the maximum number of classes/ courses a student can take and one representing the number of credits per class, which is three for all classes. It should also have three instance fields: name, a field for the student’s name, classes, a field referring to a String array that holds the class/course names the student has registered for, and, numClasses, the total number of classes the student has registered for. The constructor should create the classes array, which should be initially empty (the student has not registered for any classes yet) and initialize the other fields as well. The getNumClasses() method should return the number of classes the student has registered for, and the verifyRegistration() method should return true if the student’s registration is valid, and false otherwise. (Note: the student class does not have any information about whether the student is full-time or part-time, so it should check