bài này mình code lâu rùi nay post lên các bạn tham khảo và cho ý kiến nha
- Code:
class DateTime
{
public DateTime(byte ngay,byte thang,short nam,byte gio,byte phut)
{
this.ngay = ngay;
this.thang = thang;
this.nam = nam;
this.gio = gio;
this.phut = phut;
}
public void getDateTime(out byte ngay,out byte thang,out short nam,out byte gio,out byte phut)
{
ngay = this.ngay;
thang = this.thang;
nam = this.nam;
gio = this.gio;
phut = this.phut;
}
byte ngay;
byte thang;
short nam;
byte gio;
byte phut;
}
- Code:
using System;
class FilghtOfTrain
{
public FilghtOfTrain(DateTime ngayKhoiHanh, string hoTenKhachhang, byte soLuongve, double loaiCabin, byte loaiTau)
{
this.ngayKhoiHanh = ngayKhoiHanh;
this.hoTenKhachhang = hoTenKhachhang;
this.soLuongve = soLuongve;
this.loaiCabin = loaiCabin;
this.loaiTau = loaiTau;
}
public void HienThiNgay()
{
byte day, month, hour, minute;
short year;
ngayKhoiHanh.getDateTime(out day, out month, out year, out hour, out minute);
Console.WriteLine("{0} / {1} / {2} {3} : {4}", day, month, year, hour, minute);
}
public double TienKhuyenMai()
{
byte day, month, hour, minute;
short year;
double tienKM = 0;
ngayKhoiHanh.getDateTime(out day, out month, out year, out hour, out minute);
if (day < 20 && month < 12)
{
if (loaiTau == 1)
tienKM += 0.1 * loaiCabin * soLuongve;
if (loaiTau == 2)
tienKM += 0.1 * 2 * loaiCabin * soLuongve;
}
return tienKM;
}
public double TienTang()
{
byte day, month, hour, minute;
short year;
double tienTang = 0;
ngayKhoiHanh.getDateTime(out day, out month, out year, out hour, out minute);
if (day > 3 && day < 15 && month == 2)
{
if (loaiTau == 1)
tienTang += 0.15 * loaiCabin * soLuongve;
if (loaiTau == 2)
tienTang += 0.15 * 2 * loaiCabin * soLuongve;
}
return tienTang;
}
public double TongTienVe()
{
double t,tien;
t= loaiCabin * soLuongve * loaiTau;
if (TienTang() > 0)
tien = t + TienTang();
else
tien = t - TienKhuyenMai();
return tien;
}
public void HienThiThongTinKH()
{
Console.WriteLine("Ho ten khach hang: {0}", hoTenKhachhang);
Console.WriteLine("So luong ve: {0}", soLuongve);
Console.WriteLine("Loai ve: {0}", loaiCabin);
Console.Write("Ngay khoi hanh: "); HienThiNgay();
Console.WriteLine("Tong tien phai tra: {0}", TongTienVe());
}
DateTime ngayKhoiHanh;
string hoTenKhachhang;
byte soLuongve;
double loaiCabin;
byte loaiTau;
}
- Code:
using System;
using System.Text;
class Tester
{
public static void Main()
{
// double veNgoiCung = 300000, veNgoiMem = 340000, venNam = 400000, veNamLanh = 460000;
DateTime day = new DateTime(5, 2, 2009, 12, 30);
FilghtOfTrain ve = new FilghtOfTrain(day, "Nguyen van A", 2, 300000, 2);
Console.WriteLine("Thong tin khach hang"); ve.HienThiThongTinKH();
Console.ReadLine();
}
}