Hì mình vừa nghịch code bà i nà y hjz Có gì sai má»i ngưá»i chỉ giáo nha.
Lá»›p Employees
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
namespace Example
{
class Employees
{
int empID;
String empName;
String department;
int numWork;
public Employees(){
empID = 10;
empName = "Nguyen Van Tuyen";
department = "Aptech";
numWork = 0;
}
public Employees(int empID, String empName, String department, int numWork) {
this.empID = empID;
this.empName = empName;
this.department = department;
this.numWork = numWork;
}
public int _empID {
set { empID = value; }
get { return empID; }
}
public String _empName
{
set { empName = value; }
get { return empName; }
}
public String _department
{
set { department = value; }
get { return department; }
}
public int _numWork
{
set { numWork = value; }
get { return numWork; }
}
public void Input() {
nhap_id:
try
{
Console.Write("Input empID: ");
empID = Convert.ToInt32(Console.ReadLine());
}
catch (Exception) {
Console.WriteLine("Loi: Phai nhap vao mot so nguyen!");
goto nhap_id;
}
Console.Write("Input empName: ");
empName = Console.ReadLine();
Console.Write("Input department: ");
department = Console.ReadLine();
input_numwork:
try
{
Console.Write("Input numWork: ");
numWork = Convert.ToInt32(Console.ReadLine());
}
catch (Exception) {
Console.WriteLine("Loi: Phai nhap vao mot so nguyen!");
goto input_numwork;
}
}
public virtual void DisplayDetail() {
Console.WriteLine("empName: {0}",empName);
Console.WriteLine("department: {0}",department);
Console.WriteLine("numWork: {0}",numWork);
}
}
}
|
Lá»›p: TemporaryEmp
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
namespace Example
{
class TemporaryEmp: Employees
{
int workDay;
public TemporaryEmp():base() {
workDay = 0;
}
public void input_workDay() {
try
{
Console.WriteLine("Input workDay: ");
workDay = Convert.ToInt16(Console.ReadLine());
}
catch (Exception) {
Console.WriteLine("Loi: Phai nhap vao so nguyen!");
input_workDay();
}
}
public int CalculateSalary() {
int Salary;
if (workDay <= 25)
{
Salary = workDay * 50000;
}
else
{
Salary = 25 * 50000 + (workDay - 25) * 50000 * 2;
}
return Salary;
}
public override void DisplayDetail() {
base.DisplayDetail();
Console.WriteLine("Salary: {0}",CalculateSalary());
}
}
}
|
Lá»›p: EmployeeManagement
|
|
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace Example
{
class EmployeeManagement
{
TemporaryEmp[] list_emp = new TemporaryEmp[100];
int n;
public void inputEmployee() {
Console.Write("Input number of employees now: ");
n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < n; i++)
{
list_emp[i] = new TemporaryEmp();
nhap_lai:
list_emp[i].Input();
for (int j = 0; j < i; j++) {
if (list_emp[i]._empID == list_emp[j]._empID) {
Console.WriteLine("Nhan vien ban nhap da co.Moi ban nhap lai!");
goto nhap_lai;
}
}
list_emp[i].input_workDay();
Console.WriteLine("--------------------------------");
}
}
public void display_array_Emp() {
for (int i = 0; i < n; i++)
{
list_emp[i].DisplayDetail();
Console.WriteLine("--------------------------------");
}
}
public void display_maxNum() {
TemporaryEmp maxYear = new TemporaryEmp();
maxYear = list_emp[0];
for (int i = 1; i < n; i++) {
if (maxYear._numWork < list_emp[i]._numWork) {
maxYear = list_emp[i];
}
}
maxYear.DisplayDetail();
}
}
}
|
Lá»›p: Test
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
namespace Example
{
class Test
{
EmployeeManagement empMng = new EmployeeManagement();
void menu() {
int choose;
do
{
Console.WriteLine("press 1 to enter Array Employee");
Console.WriteLine("press 2 to display array of Employee");
Console.WriteLine("press 3 to display array of Employee has max number of years working.");
Console.WriteLine("press 4 to exit");
Console.WriteLine("Input: ");
choose = Convert.ToInt16(Console.ReadLine());
switch (choose)
{
case 1:
Console.WriteLine("Nhap mang nhan vien!");
empMng.inputEmployee();
break;
case 2:
Console.WriteLine("Hien thi mang nhan vien!");
empMng.display_array_Emp();
break;
case 3:
Console.WriteLine("Hien thi nhan vien co so nam kinh nghiem nhieu nhat!");
empMng.display_maxNum();
break;
case 4:
Console.WriteLine("Exit the program!");
break;
default:
Console.WriteLine("Input fail!");
break;
}
Console.ReadKey();
Console.Clear();
} while (choose != 4);
}
static void Main(string[] args)
{
Test t = new Test();
t.menu();
}
}
}
|
[right][size=1][url=http://bachkhoaaptech.com/forum/showthread.php?p=19977]Copyright © Diá»…n Äà n BachKhoa-Aptech - Posted by Perfect_Love[/url][/size][/right]