Commit f73a23d5 by Paktalin

Lesson 2 is done

parent 8d5faa1a
......@@ -8,14 +8,6 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
android:theme="@style/AppTheme"></application>
</manifest>
\ No newline at end of file
package com.example.paktalin.agilejava;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* Created by Paktalin on 16/05/2018.
*/
class CourseSession {
private String department;
private String number;
private ArrayList<Student> students = new ArrayList<>();
private Date startDate;
CourseSession(String department, String number) {
this.department = department;
this.number = number;
}
CourseSession(String department, String number, Date startDate) {
this.department = department;
this.number = number;
this.startDate = startDate;
}
String getDepartment() {
return department;
}
String getNumber() {
return number;
}
void enroll(Student student) {
students.add(student);
}
Student get(int index) {
return students.get(index);
}
int getNumberOfStudents() {
return students.size();
}
Date getEndDate() {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(startDate);
calendar.add(Calendar.DAY_OF_YEAR, getNumberOfDays());
return calendar.getTime();
}
Date getStartDate() {
return startDate;
}
private int getNumberOfDays() {
final int sessionLength = 16;
final int daysInWeek = 7;
final int daysFromFridayToMonday = 3;
return sessionLength * daysInWeek - daysFromFridayToMonday;
}
}
package com.example.paktalin.agilejava;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
package com.example.paktalin.agilejava;
import junit.framework.TestSuite;
/**
* Created by Paktalin on 16/05/2018.
*/
public class AllTests extends TestSuite {
public static TestSuite suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(StudentTest.class);
suite.addTestSuite(CourseSessionTest.class);
return suite;
}
}
package com.example.paktalin.agilejava;
import junit.framework.TestCase;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* Created by Paktalin on 16/05/2018.
*/
public class CourseSessionTest extends TestCase {
private CourseSession session;
private Date startDate;
public void setUp() {
startDate = createDate(2003, 1, 6);
session = new CourseSession("ENGL", "101", startDate);
}
public void testCreate() {
assertEquals("ENGL", session.getDepartment());
assertEquals("101", session.getNumber());
assertEquals(0, session.getNumberOfStudents());
assertEquals(startDate, session.getStartDate());
}
public void testEnrollStudents() {
Student student1 = new Student("Cain DiVoe");
session.enroll(student1);
assertEquals(student1, session.get(0));
assertEquals(1, session.getNumberOfStudents());
Student student2 = new Student("Coralee DeVaughn");
session.enroll(student2);
assertEquals(student2, session.get(1));
assertEquals(2, session.getNumberOfStudents());
}
public void testCourseDates() {
Date sixteenWeeksOut = createDate(2003, 4, 25);
assertEquals(sixteenWeeksOut, session.getEndDate());
}
private Date createDate(int year, int month, int date) {
GregorianCalendar calendar = new GregorianCalendar();
calendar.clear();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, date);
return calendar.getTime();
}
}
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