Commit f20ab55b by Paktalin

Lesson 3 is done

parent 0f8d14f1
......@@ -10,7 +10,7 @@ import java.util.GregorianCalendar;
class DateUtil {
Date createDate(int year, int month, int date) {
static Date createDate(int year, int month, int date) {
GregorianCalendar calendar = new GregorianCalendar();
calendar.clear();
calendar.set(Calendar.YEAR, year);
......
......@@ -7,29 +7,38 @@ package com.example.paktalin.agilejava;
class RosterReporter {
static final String NEW_LINE = System.getProperty("line.separator");
static String ROSTER_REPORT_HEADER = "Student" + NEW_LINE +
"_____" + NEW_LINE;
static String ROSTER_REPORT_HEADER = "Student" + NEW_LINE + "_____" + NEW_LINE;
static String ROSTER_REPORT_FOOTER = NEW_LINE + "# students = ";
private CourseSession session;
private StringBuilder buffer;
RosterReporter(CourseSession session) {
this.session = session;
}
String getReport() {
buffer = new StringBuilder();
writeHeader();
writeBody();
writeFooter();
String getReport() {
StringBuilder buffer = new StringBuilder();
return buffer.toString();
}
private void writeHeader() {
buffer.append(ROSTER_REPORT_HEADER);
}
private void writeBody() {
for (Student student : session.getAllStudents()) {
buffer.append(student.getName());
buffer.append(NEW_LINE);
}
}
private void writeFooter() {
buffer.append(ROSTER_REPORT_FOOTER + session.getAllStudents().size() + NEW_LINE);
return buffer.toString();
}
}
......@@ -14,7 +14,7 @@ public class CourseSessionTest extends TestCase {
private Date startDate;
public void setUp() {
startDate = new DateUtil().createDate(2003, 1, 6);
startDate = DateUtil.createDate(2003, 1, 6);
session = new CourseSession("ENGL", "101", startDate);
}
......@@ -38,7 +38,7 @@ public class CourseSessionTest extends TestCase {
}
public void testCourseDates() {
Date sixteenWeeksOut = new DateUtil().createDate(2003, 4, 25);
Date sixteenWeeksOut = DateUtil.createDate(2003, 4, 25);
assertEquals(sixteenWeeksOut, session.getEndDate());
}
}
......@@ -11,12 +11,14 @@ public class RosterReporterTest extends TestCase {
public void testRosterReport() {
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("B"));
String rosterReport = new RosterReporter(session).getReport();
System.out.println(rosterReport);
assertEquals(
RosterReporter.ROSTER_REPORT_HEADER +
"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