Commit ce57dcf8 by Paktalin

Small refactoring in Lesson 6

parent d478a696
...@@ -34,16 +34,16 @@ public abstract class Session implements Comparable<Session>{ ...@@ -34,16 +34,16 @@ public abstract class Session implements Comparable<Session>{
return this.getNumber().compareTo(that.getNumber()); return this.getNumber().compareTo(that.getNumber());
} }
protected void setNumberOfCredits(int numberOfCredits) { void setNumberOfCredits(int numberOfCredits) {
this.numberOfCredits = numberOfCredits; this.numberOfCredits = numberOfCredits;
} }
public void enroll(Student student) { void enroll(Student student) {
students.add(student); students.add(student);
student.addCredits(numberOfCredits); student.addCredits(numberOfCredits);
} }
public Date getEndDate() { Date getEndDate() {
GregorianCalendar calendar = new GregorianCalendar(); GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(getStartDate()); calendar.setTime(getStartDate());
calendar.add(Calendar.DAY_OF_YEAR, getNumberOfDaysInSession()); calendar.add(Calendar.DAY_OF_YEAR, getNumberOfDaysInSession());
...@@ -56,7 +56,7 @@ public abstract class Session implements Comparable<Session>{ ...@@ -56,7 +56,7 @@ public abstract class Session implements Comparable<Session>{
return getSessionLength() * daysInWeek - daysFromFridayToMonday; return getSessionLength() * daysInWeek - daysFromFridayToMonday;
} }
public List<Student> getAllStudents() { List<Student> getAllStudents() {
return students; return students;
} }
...@@ -68,10 +68,10 @@ public abstract class Session implements Comparable<Session>{ ...@@ -68,10 +68,10 @@ public abstract class Session implements Comparable<Session>{
int getNumberOfStudents() { int getNumberOfStudents() {
return students.size(); return students.size();
} }
public String getDepartment() { String getDepartment() {
return department; return department;
} }
public String getNumber() { String getNumber() {
return number; return number;
} }
Student get(int index) { Student get(int index) {
......
...@@ -36,4 +36,4 @@ public class SummerCourseSession extends Session { ...@@ -36,4 +36,4 @@ public class SummerCourseSession extends Session {
protected int getSessionLength() { protected int getSessionLength() {
return 8; return 8;
} }
} }
\ No newline at end of file
...@@ -22,7 +22,7 @@ public class CourseSessionTest extends SessionTest { ...@@ -22,7 +22,7 @@ public class CourseSessionTest extends SessionTest {
} }
@Override @Override
protected Date calculateEndDate() { protected Date getExpectedEndDate() {
return DateUtil.createDate(2003, 4, 25); return DateUtil.createDate(2003, 4, 25);
} }
} }
...@@ -22,6 +22,7 @@ abstract public class SessionTest extends TestCase { ...@@ -22,6 +22,7 @@ abstract public class SessionTest extends TestCase {
} }
protected abstract Session createSession(String department, String number, Date startDate); protected abstract Session createSession(String department, String number, Date startDate);
protected abstract Date getExpectedEndDate();
public void testCreate() { public void testCreate() {
assertEquals("ENGL", session.getDepartment()); assertEquals("ENGL", session.getDepartment());
...@@ -62,8 +63,6 @@ abstract public class SessionTest extends TestCase { ...@@ -62,8 +63,6 @@ abstract public class SessionTest extends TestCase {
public void testCourseDates() { public void testCourseDates() {
Date startDate = DateUtil.createDate(2003, 1, 6); Date startDate = DateUtil.createDate(2003, 1, 6);
Session session = createSession("ENGL", "200", startDate); Session session = createSession("ENGL", "200", startDate);
assertEquals(calculateEndDate(), session.getEndDate()); assertEquals(getExpectedEndDate(), session.getEndDate());
} }
protected abstract Date calculateEndDate();
} }
...@@ -24,7 +24,7 @@ public class SummerCourseSessionTest extends SessionTest { ...@@ -24,7 +24,7 @@ public class SummerCourseSessionTest extends SessionTest {
} }
@Override @Override
protected Date calculateEndDate() { protected Date getExpectedEndDate() {
return DateUtil.createDate(2003, 2, 28); return DateUtil.createDate(2003, 2, 28);
} }
......
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