- Code:
using System;
class NhanVien
{
public NhanVien(string hoVaTen, DateTime ngaySinh, DateTime ngayvaoCongTy, string soDienThoai, double heSoLuong, int luongCoBan)
{
this.hoVaTen = hoVaTen;
this.ngaySinh = ngaySinh;
this.ngayVaoCongTy = ngayvaoCongTy;
this.soDienThoai = soDienThoai;
this.heSoLuong = heSoLuong;
NhanVien.luongCoBan = luongCoBan;
}
public NhanVien(string hoVaTen, DateTime ngaySinh, DateTime ngayvaoCongTy, string soDienThoai, double heSoLuong)
{
this.hoVaTen = hoVaTen;
this.ngaySinh = ngaySinh;
this.ngayVaoCongTy = ngayvaoCongTy;
this.soDienThoai = soDienThoai;
this.heSoLuong = heSoLuong;
}
public NhanVien(string hoVaTen, DateTime ngaySinh, DateTime ngayvaoCongTy, double heSoLuong, int luongCoBan)
{
this.hoVaTen = hoVaTen;
this.ngaySinh = ngaySinh;
this.ngayVaoCongTy = ngayvaoCongTy;
this.heSoLuong = heSoLuong;
NhanVien.luongCoBan = luongCoBan;
this.soDienThoai = "khong co so dien thoai";
}
public void HienThiThongTin()
{
Console.WriteLine("Ho va ten nhan vien: {0}", hoVaTen);
Console.WriteLine("Ngay sinh: {0}/{1}/{2}", ngaySinh.Day, ngaySinh.Month, ngaySinh.Year);
Console.WriteLine("Ngay vao cong ty: {0}/{1}/{2}", ngayVaoCongTy.Day, ngayVaoCongTy.Month, ngayVaoCongTy.Year);
Console.WriteLine("So dien thoai: {0}", soDienThoai);
Console.WriteLine("He so luong: {0}", heSoLuong);
Console.WriteLine("Luong co ban: {0}", luongCoBan);
}
public DateTime NgayVaoCongTy
{
get { return ngayVaoCongTy; }
set { ngayVaoCongTy = value; }
}
public string TenNhanVien()
{
string[] s = hoVaTen.Split(' ');
return s[s.Length - 1];
}
public int ThamNien()
{
int soThang, soNam;
DateTime tgHienTai = DateTime.Now;
soThang = (tgHienTai.Year - ngayVaoCongTy.Year) * 12 + (tgHienTai.Month - ngayVaoCongTy.Month);
soNam = soThang / 12;
if (soThang % 12 > 5)
soNam++;
return soNam;
}
public double TienThuong()
{
double tienThuong;
if (ThamNien() < 1)
tienThuong = 0;
if (ThamNien() >= 1 && ThamNien() < 6)
tienThuong = ThamNien() * luongCoBan;
else
tienThuong = 6 * luongCoBan;
return tienThuong;
}
public double TienLuongTruocThue()
{
return TienThuong() + heSoLuong * luongCoBan;
}
public double TienBaoHiem()
{
return 0.07 * heSoLuong * luongCoBan;
}
public double ThuNhapChiuThue()
{
double giamTruGiaCanh = 4000000, tienThue;
tienThue = TienLuongTruocThue() - giamTruGiaCanh - TienBaoHiem();
if (tienThue < 0)
tienThue = 0;
return tienThue;
}
public double TienThueThuNhapCaNhan()
{
double tien, trieu = 1000000;
if (ThuNhapChiuThue() <= 5 * trieu)
tien = 0.05 * ThuNhapChiuThue();
else
if (ThuNhapChiuThue() > 5 * trieu && ThuNhapChiuThue() <= 10 * trieu)
tien = 0.05 * 5 * trieu + (ThuNhapChiuThue() - 5 * trieu) * 0.1;
else
if (ThuNhapChiuThue() > 10 * trieu && ThuNhapChiuThue() <= 18 * trieu)
tien = 0.15 * (5 * trieu + ThuNhapChiuThue() - 10 * trieu);
else
if (ThuNhapChiuThue() > 18 * trieu && ThuNhapChiuThue() <= 32 * trieu)
tien = 0.15 * 13 * trieu + (ThuNhapChiuThue() - 18 * trieu) * 0.2;
else
if (ThuNhapChiuThue() > 32 * trieu && ThuNhapChiuThue() <= 52 * trieu)
tien = 0.15 * 13 * trieu + 0.20 * 14 * trieu + (ThuNhapChiuThue() - 32 * trieu) * 0.25;
else
if (ThuNhapChiuThue() > 52 * trieu && ThuNhapChiuThue() <= 80 * trieu)
tien = 0.15 * 13 * trieu + 0.20 * 14 * trieu + 0.25 * 20 * trieu + (ThuNhapChiuThue() - 52 * trieu) * 0.3;
else
tien = 0.15 * 13 * trieu + 0.20 * 14 * trieu + 0.25 * 20 * trieu + 0.3 * 28 * trieu + (ThuNhapChiuThue() - 80 * trieu) * 0.35;
return tien;
}
public double TienLuongThucLanh()
{
double tien, trieu = 1000000;
tien = TienLuongTruocThue() - TienBaoHiem() - TienThueThuNhapCaNhan();
if (tien < 2 * trieu)
tien = 2 * trieu;
return tien;
}
public readonly string hoVaTen;
DateTime ngaySinh;
DateTime ngayVaoCongTy;
string soDienThoai;
double heSoLuong;
public static int luongCoBan = 512000;
}
- Code:
using System;
class Tester
{
public static void Main()
{
/*
// cau a
string nV, soDT;
int ng, th, n, ng1, th1, n1;
double heSoLuong;
Console.Write("Nhap ho ten nhan vien: ");
nV = Convert.ToString(Console.ReadLine());
Console.WriteLine("Nhap ngay sinh nhan vien");
Console.Write("Nhap ngay sinh: ");
ng = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap thang sinh: ");
th = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap nam sinh: ");
n = Convert.ToInt32(Console.ReadLine());
DateTime d=new DateTime(n,th,ng);
Console.WriteLine("Nhap ngay nhan vien vao cong ty");
Console.Write("Nhap ngay vao: ");
ng1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap thang vao: ");
th1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap nam vao: ");
n1 = Convert.ToInt32(Console.ReadLine());
DateTime d1 = new DateTime(n1,th1,ng1);
Console.Write("Nhap so dien thoai: ");
soDT = Convert.ToString(Console.ReadLine());
Console.Write("He so luong: ");
heSoLuong = Convert.ToDouble(Console.ReadLine());
NhanVien a = new NhanVien(nV, d, d1, soDT, heSoLuong, 512000);
Console.WriteLine(""); a.HienThiThongTin();
Console.WriteLine("\nTen nhan vien: "+a.TenNhanVien());
Console.WriteLine("Tham nien la: " +a.ThamNien());
Console.WriteLine("Tien thuong: " + a.TienThuong());
Console.WriteLine("Tien luong truoc thue: " + a.TienLuongTruocThue());
Console.WriteLine("Tien bao hiem: " + a.TienBaoHiem());
Console.WriteLine("Thu nhap chiu thue: " + a.ThuNhapChiuThue());
Console.WriteLine("Tien thue thu nhap ca nhan: " + a.TienThueThuNhapCaNhan());
Console.WriteLine("Tien luong thuc lanh: " + a.TienLuongThucLanh());
// cau b
DateTime a1 = new DateTime(1990, 6, 3);
DateTime a2 = new DateTime(2001,5,5);
NhanVien a = new NhanVien("Nguyen van A", a1, a2,"01234567890", (float)8.5, 512000);
Console.WriteLine("Thong tin nhan vien");
Console.WriteLine(""); a.HienThiThongTin();
Console.WriteLine("Ten nhan vien: " + a.TenNhanVien());
Console.WriteLine("Tham nien la: " + a.ThamNien());
Console.WriteLine("Tien thuong: " + a.TienThuong());
Console.WriteLine("Tien luong truoc thue: " + a.TienLuongTruocThue());
Console.WriteLine("Tien bao hiem: " + a.TienBaoHiem());
Console.WriteLine("Thu nhap chiu thue: " + a.ThuNhapChiuThue());
Console.WriteLine("Tien thue thu nhap ca nhan: " + a.TienThueThuNhapCaNhan());
Console.WriteLine("Tien luong thuc lanh: " + a.TienLuongThucLanh());
DateTime b1 = new DateTime(1990, 6, 3);
DateTime b2 = new DateTime(2001, 5, 5);
NhanVien b = new NhanVien("Nguyen van B", b1, b2, "01234567890", (float)25.5, 512000);
Console.WriteLine(""); b.HienThiThongTin();
Console.WriteLine("Ten nhan vien: " + b.TenNhanVien());
Console.WriteLine("Tham nien la: " + b.ThamNien());
Console.WriteLine("Tien thuong: " + b.TienThuong());
Console.WriteLine("Tien luong truoc thue: " + b.TienLuongTruocThue());
Console.WriteLine("Tien bao hiem: " + b.TienBaoHiem());
Console.WriteLine("Thu nhap chiu thue: " + b.ThuNhapChiuThue());
Console.WriteLine("Tien thue thu nhap ca nhan: " + b.TienThueThuNhapCaNhan());
Console.WriteLine("Tien luong thuc lanh: " + b.TienLuongThucLanh());
DateTime c1 = new DateTime(1990, 6, 3);
DateTime c2 = new DateTime(2008, 5, 5);
NhanVien c = new NhanVien("Nguyen van C", c1, c2, "01234567890", (float)1.5, 512000);
Console.WriteLine(""); c.HienThiThongTin();
Console.WriteLine("Ten nhan vien: " + c.TenNhanVien());
Console.WriteLine("Tham nien la: " + c.ThamNien());
Console.WriteLine("Tien thuong: " + c.TienThuong());
Console.WriteLine("Tien luong truoc thue: " + c.TienLuongTruocThue());
Console.WriteLine("Tien bao hiem: " + c.TienBaoHiem());
Console.WriteLine("Thu nhap chiu thue: " + c.ThuNhapChiuThue());
Console.WriteLine("Tien thue thu nhap ca nhan: " + c.TienThueThuNhapCaNhan());
Console.WriteLine("Tien luong thuc lanh: " + c.TienLuongThucLanh());
*/
// cau c
string nV, soDT;
int ng, th, n, ng1, th1, n1;
double heSoLuong;
int luongCoBan;
Console.Write("Nhap ho ten nhan vien: ");
nV = Convert.ToString(Console.ReadLine());
Console.WriteLine("Nhap ngay sinh nhan vien");
Console.Write("Nhap ngay sinh: ");
ng = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap thang sinh: ");
th = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap nam sinh: ");
n = Convert.ToInt32(Console.ReadLine());
DateTime d = new DateTime(n, th, ng);
Console.WriteLine("Nhap ngay nhan vien vao cong ty");
Console.Write("Nhap ngay vao: ");
ng1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap thang vao: ");
th1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap nam vao: ");
n1 = Convert.ToInt32(Console.ReadLine());
DateTime d1 = new DateTime(n1, th1, ng1);
nhapSoDienThoai:
double num;
Console.WriteLine("Nhap so dien thoai: ");
soDT = Console.ReadLine();
bool isNum = double.TryParse(soDT, out num);
if (!isNum)
{
Console.WriteLine("So dien thoai chi la so");
goto nhapSoDienThoai;
}
Console.Write("He so luong: ");
heSoLuong = Convert.ToDouble(Console.ReadLine());
nhapLuongCoBan:
try
{
Console.WriteLine("Nhap luong co ban");
luongCoBan = Convert.ToInt32(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("Ban hay nhap bang so");
goto nhapLuongCoBan;
}
NhanVien a = new NhanVien(nV, d, d1, soDT, heSoLuong,luongCoBan);
Console.WriteLine(""); a.HienThiThongTin();
Console.WriteLine("Ten nhan vien: " + a.TenNhanVien());
Console.WriteLine("Tham nien la: " + a.ThamNien());
Console.WriteLine("Tien thuong: " + a.TienThuong());
Console.WriteLine("Tien luong truoc thue: " + a.TienLuongTruocThue());
Console.WriteLine("Tien bao hiem: " + a.TienBaoHiem());
Console.WriteLine("Thu nhap chiu thue: " + a.ThuNhapChiuThue());
Console.WriteLine("Tien thue thu nhap ca nhan: " + a.TienThueThuNhapCaNhan());
Console.WriteLine("Tien luong thuc lanh: " + a.TienLuongThucLanh());
Console.ReadLine();
}
}