You are on page 1of 3

//CompositionTest

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Employee
{
public class CompositionTest
{
public void Main()
{
Employee e =
new Employee("Bob", "Jones", 2, 2, 1989, 3, 12, 2016);

MessageBox.Show(e.ToEmployeeString(), "Testing Class Employee");

}
}
}

//Employee
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Employee
{
public class Employee
{
public string firstName;
public string lastName;
public Date birthDate;
public Date hireDate;

public Employee(string first, string last, int birthDay, int birthMonth, int
birthYear, int hireDay, int hireMonth, int hireYear)
{
firstName = first;
lastName = last;
birthDate = new Date(birthMonth, birthDay, birthYear);
hireDate = new Date(hireMonth, hireDay, hireYear);

public string ToEmployeeString()


{
return lastName + " , " + firstName + " Hire: " + hireDate.ToDateString() + "
Birthday: " + birthDate.ToDateString();
}
}
}

//Date
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Employee
{
public class Date
{
private int day;
private int month;
private int year;

public Date(int theMonth, int theDay, int theYear)


{
if (theMonth > 0 && theMonth < 12)
month = theMonth;
else
{
month = 1;
Console.WriteLine("Thang {0} khong hop le. Tam thoi dua ve 1", theMonth);
}
year = theYear;
day = CheckDay(theDay);

public int CheckDay(int testDay)


{
int[] daysPerMonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (testDay > 0 && testDay <= daysPerMonth[month])
return testDay;
if (month == 2 && testDay == 29 && (year % 400 == 0 || (year % 4 == 0 && year
% 100 != 0)))
return testDay;
Console.WriteLine("Ngay {0} khong hop le tam thoi dua ve 1", testDay);
return 1;

public string ToDateString()


{
return month + "/" + day + "/" + year;
}
}
}
//Form 1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Employee
{
public partial class Form1 : Form
{
public Form1()
{
Employee e =
new Employee("Bob", "Jones", 2, 2, 1989, 3, 12, 2016);

MessageBox.Show(e.ToEmployeeString(), "Testing Class Employee");


}
}
}

You might also like