To get started, get a simple report working of all course sessions. Don't worry yet about its order. package sis.report; import junit.framework.*; import java.util.*; import sis.studentinfo.*; import static sis.report.ReportConstant.NEWLINE; public class CourseReportTest extends TestCase { public void testReport() { final Date date = new Date(); CourseReport report = new CourseReport(); report.add(CourseSession.create("ENGL", "101", date)); report.add(CourseSession.create("CZEC", "200", date)); report.add(CourseSession.create("ITAL", "410", date)); assertEquals( "ENGL 101" + NEWLINE + "CZEC 200" + NEWLINE + "ITAL 410" + NEWLINE, report.text()); } } The report is bare boned, showing simply a course department and number on each line. Currently the report lists sessions in the order in which you added them to the CourseReport object. The production class, CourseReport, looks similar to RosterReporter: package sis.report; import java.util.*; import sis.studentinfo.*; import static sis.report.ReportConstant.NEWLINE; public class CourseReport { private ArrayList<CourseSession> sessions = new ArrayList<CourseSession>(); public void add(CourseSession session) { sessions.add(session); } public String text() { StringBuilder builder = new StringBuilder(); for (CourseSession session: sessions) builder.append( session.getDepartment() + " " + session.getNumber() + NEWLINE); return builder.toString(); } } In order to get CourseReport to compile, you'll have to designate the CourseSession methods getdepartment and getNumber as public. |