Commit fb332f27 by Paktalin

SummerCourseSession created (Lesson 6 in progress)

parent b1321304
......@@ -12,7 +12,7 @@ import java.util.List;
* Created by Paktalin on 16/05/2018.
*/
class CourseSession implements Comparable<CourseSession>{
public class CourseSession implements Comparable<CourseSession>{
private String department;
private String number;
private List<Student> students = new ArrayList<>();
......@@ -20,7 +20,7 @@ class CourseSession implements Comparable<CourseSession>{
private static int count = 0;
private int numberOfCredits;
private CourseSession(String department, String number, Date startDate) {
protected CourseSession(String department, String number, Date startDate) {
this.department = department;
this.number = number;
this.startDate = startDate;
......@@ -55,22 +55,24 @@ class CourseSession implements Comparable<CourseSession>{
return students.size();
}
Date getEndDate() {
public Date getEndDate() {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(startDate);
calendar.add(Calendar.DAY_OF_YEAR, getNumberOfDays());
calendar.setTime(getStartDate());
calendar.add(Calendar.DAY_OF_YEAR, getNumberOfDaysInSession());
return calendar.getTime();
}
Date getStartDate() {
protected Date getStartDate() {
return startDate;
}
protected int getSessionLength() {
return 16;
}
private int getNumberOfDays() {
final int sessionLength = 16;
protected int getNumberOfDaysInSession() {
final int daysInWeek = 7;
final int daysFromFridayToMonday = 3;
return sessionLength * daysInWeek - daysFromFridayToMonday;
return getSessionLength() * daysInWeek - daysFromFridayToMonday;
}
List<Student> getAllStudents() {
......
......@@ -8,7 +8,7 @@ import java.util.GregorianCalendar;
* Created by Paktalin on 17/05/2018.
*/
class DateUtil {
public class DateUtil {
//That's how static initialization block works
static {
......@@ -20,7 +20,7 @@ class DateUtil {
private DateUtil() {}
static Date createDate(int year, int month, int date) {
public static Date createDate(int year, int month, int date) {
GregorianCalendar calendar = new GregorianCalendar();
calendar.clear();
calendar.set(Calendar.YEAR, year);
......
package com.example.paktalin.agilejava.summer;
import com.example.paktalin.agilejava.CourseSession;
import java.util.Date;
/**
* Created by Paktalin on 28/05/2018.
*/
public class SummerCourseSession extends CourseSession {
static SummerCourseSession create(String department, String number, Date startDate) {
return new SummerCourseSession(department, number, startDate);
}
private SummerCourseSession(String department, String number, Date startDate) {
super(department, number, startDate);
}
@Override
protected int getSessionLength() {
return 8;
}
}
package com.example.paktalin.agilejava;
import com.example.paktalin.agilejava.language_tests.LanguageTests;
import com.example.paktalin.agilejava.language_tests.SuperClassTest;
import junit.framework.TestSuite;
/**
......@@ -19,6 +22,7 @@ public class AllTests extends TestSuite {
suite.addTestSuite(ReportCardTest.class);
suite.addTestSuite(BasicGradingStrategyTest.class);
suite.addTestSuite(HonorsGradingStrategyTest.class);
suite.addTestSuite(SuperClassTest.class);
return suite;
}
}
package com.example.paktalin.agilejava;
package com.example.paktalin.agilejava.language_tests;
import junit.framework.TestCase;
......
package com.example.paktalin.agilejava.language_tests;
import junit.framework.TestCase;
/**
* Created by Paktalin on 28/05/2018.
*/
public class SuperClassTest extends TestCase {
public void testConstructorCalls() {
SuperClass superClass = new SubClass("parm");
assertTrue(superClass.constructorWasCalled);
}
class SuperClass {
boolean constructorWasCalled = false;
SuperClass(String parm) {
constructorWasCalled = true;
}
}
class SubClass extends SuperClass {
SubClass(String parm) {
super(parm);
}
}
}
package com.example.paktalin.agilejava.summer;
import com.example.paktalin.agilejava.CourseSession;
import com.example.paktalin.agilejava.DateUtil;
import junit.framework.TestCase;
import java.util.Date;
/**
* Created by Paktalin on 28/05/2018.
*/
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());
}
}
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