Commit f20ab55b by Paktalin

Lesson 3 is done

parent 0f8d14f1
...@@ -10,7 +10,7 @@ import java.util.GregorianCalendar; ...@@ -10,7 +10,7 @@ import java.util.GregorianCalendar;
class DateUtil { class DateUtil {
Date createDate(int year, int month, int date) { static Date createDate(int year, int month, int date) {
GregorianCalendar calendar = new GregorianCalendar(); GregorianCalendar calendar = new GregorianCalendar();
calendar.clear(); calendar.clear();
calendar.set(Calendar.YEAR, year); calendar.set(Calendar.YEAR, year);
......
...@@ -7,29 +7,38 @@ package com.example.paktalin.agilejava; ...@@ -7,29 +7,38 @@ package com.example.paktalin.agilejava;
class RosterReporter { class RosterReporter {
static final String NEW_LINE = System.getProperty("line.separator"); static final String NEW_LINE = System.getProperty("line.separator");
static String ROSTER_REPORT_HEADER = "Student" + NEW_LINE + static String ROSTER_REPORT_HEADER = "Student" + NEW_LINE + "_____" + NEW_LINE;
"_____" + NEW_LINE;
static String ROSTER_REPORT_FOOTER = NEW_LINE + "# students = "; static String ROSTER_REPORT_FOOTER = NEW_LINE + "# students = ";
private CourseSession session; private CourseSession session;
private StringBuilder buffer;
RosterReporter(CourseSession session) { RosterReporter(CourseSession session) {
this.session = session; this.session = session;
} }
String getReport() {
buffer = new StringBuilder();
writeHeader();
writeBody();
writeFooter();
String getReport() { return buffer.toString();
StringBuilder buffer = new StringBuilder(); }
private void writeHeader() {
buffer.append(ROSTER_REPORT_HEADER); buffer.append(ROSTER_REPORT_HEADER);
}
private void writeBody() {
for (Student student : session.getAllStudents()) { for (Student student : session.getAllStudents()) {
buffer.append(student.getName()); buffer.append(student.getName());
buffer.append(NEW_LINE); buffer.append(NEW_LINE);
} }
}
private void writeFooter() {
buffer.append(ROSTER_REPORT_FOOTER + session.getAllStudents().size() + NEW_LINE); buffer.append(ROSTER_REPORT_FOOTER + session.getAllStudents().size() + NEW_LINE);
return buffer.toString();
} }
} }
...@@ -14,7 +14,7 @@ public class CourseSessionTest extends TestCase { ...@@ -14,7 +14,7 @@ public class CourseSessionTest extends TestCase {
private Date startDate; private Date startDate;
public void setUp() { public void setUp() {
startDate = new DateUtil().createDate(2003, 1, 6); startDate = DateUtil.createDate(2003, 1, 6);
session = new CourseSession("ENGL", "101", startDate); session = new CourseSession("ENGL", "101", startDate);
} }
...@@ -38,7 +38,7 @@ public class CourseSessionTest extends TestCase { ...@@ -38,7 +38,7 @@ public class CourseSessionTest extends TestCase {
} }
public void testCourseDates() { public void testCourseDates() {
Date sixteenWeeksOut = new DateUtil().createDate(2003, 4, 25); Date sixteenWeeksOut = DateUtil.createDate(2003, 4, 25);
assertEquals(sixteenWeeksOut, session.getEndDate()); assertEquals(sixteenWeeksOut, session.getEndDate());
} }
} }
...@@ -11,12 +11,14 @@ public class RosterReporterTest extends TestCase { ...@@ -11,12 +11,14 @@ public class RosterReporterTest extends TestCase {
public void testRosterReport() { public void testRosterReport() {
CourseSession session = new CourseSession("ENGL", "101", CourseSession session = new CourseSession("ENGL", "101",
new DateUtil().createDate(2003, 1, 6)); DateUtil.createDate(2003, 1, 6));
session.enroll(new Student("A")); session.enroll(new Student("A"));
session.enroll(new Student("B")); session.enroll(new Student("B"));
String rosterReport = new RosterReporter(session).getReport(); String rosterReport = new RosterReporter(session).getReport();
System.out.println(rosterReport);
assertEquals( assertEquals(
RosterReporter.ROSTER_REPORT_HEADER + RosterReporter.ROSTER_REPORT_HEADER +
"A" + RosterReporter.NEW_LINE + "A" + RosterReporter.NEW_LINE +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment