One solution would be to pass the session length into the CourseSession class, store it, and use it as a multiplier when calculating the session end date. However, there are many other differences between summer sessions and spring/fall sessions, including differences in maximum class session, credit values, and so on. For this reason, you have chosen to create a new class named SummerCourseSession. The simplest approach for implementing SummerCourseSession, given what you know, is to have it extend from CourseSession. A SummerCourseSession is a CourseSession with some refinement on the details (see Figure 6.2). Figure 6.2. SummerCourseSession SpecializationYou want to create the SummerCourseSession classes (test and production) in a new package, summer, for organizational purposes. The test you initially code verifies that SummerCourseSession calculates the course end date correctly: package sis.summer; import junit.framework.*; import java.util.*; import sis.studentinfo.*; public class SummerCourseSessionTest extends TestCase { public void testEndDate() { Date startDate = DateUtil.createDate(2003, 6, 9); CourseSession session = SummerCourseSession.create("ENGL", "200", startDate); Date eightWeeksOut = DateUtil.createDate(2003, 8, 1); assertEquals(eightWeeksOut, session.getEndDate()); } } |