By GokiSoft.com| 09:53 07/10/2021|
C Sharp

Chương trình quản lý công nhân - Lập Trình C# - Lập Trình C Sharp - Làm quen OOP BT1432

Cài đặt lớp Employee gồm các thông tin:

-       Họ tên             (String)

-       Giới tính          (String) (Nhận 3 giá trị Nam, Nữ, Ko biết)

-       Quê quán        (String)

-       Chức vụ          (String)

-       Lương             (double) => Dữ liệu là số dương

 

Cài đặt 2 constructors.

Cài đặt các phương thức set/get cho các thuộc tính

Cài đặt hàm nhập, hiển thị.

Cài đặt lớp Test, có hàm main:

Khai báo 2 đối tượng của lớp.

1 đối tượng gọi constructor có tham số. 1 đối tượng gọi constructor không có tham số (phải gọi hàm nhập để lấy thông tin).

Gọi hàm hiển thị để hiển thị kết quả.

Liên kết rút gọn:

https://gokisoft.com/1432

Bình luận

avatar
Nguyễn Hùng Anh [community,C2009G]
2021-10-07 04:28:06


#Employee.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace Lesson02.bt1432
{
    class Employee
    {
        public string Name { get; set; }
        private string _gender;
        public string Gender
        {
            get
            {
                return _gender;
            }
            set
            {
                if(value == "Nam" || value == "Nu")
                {
                    this._gender = value;
                } else
                {
                    Console.WriteLine("Gioi tinh: Khong biet");
                    this._gender = "Khong biet";
                }
            }
        }
        public string HomeTown { get; set; }
        public string Regency { get; set; }
        private int _salary;
        public int Salary 
        {
            get
            {
                return _salary;
            }
            set
            {
                if(value > 0)
                {
                    this._salary = value;
                } else
                {
                    Console.WriteLine("Luong phai la so duong");
                }
            }
        }

        public Employee()
        {

        }

        public Employee(string name, string gender, string hometown, string regency, int salary)
        {
            Name = name;
            Gender = gender;
            HomeTown = hometown;
            Regency = regency;
            Salary = salary;
        }

        public void Input()
        {
            Console.WriteLine("Nhap ten cong nhan: ");
            Name = Console.ReadLine();

            Console.WriteLine("Nhap gioi tinh: ");
            Gender = Console.ReadLine();

            Console.WriteLine("Nhap que quan: ");
            HomeTown = Console.ReadLine();

            Console.WriteLine("Nhap chuc vu: ");
            Regency = Console.ReadLine();

            Console.WriteLine("Nhap tien luong: ");
            Salary = int.Parse(Console.ReadLine());
        }

        public void Display()
        {
            Console.WriteLine(this);
        }

        public override string ToString()
        {
            return "Ten: " + Name + ", Gioi tinh: " + Gender + ", Que quan: " + HomeTown +
                ", Chuc vu: " + Regency + ", Tien luong: " + Salary;
        }
    }
}


#Program.cs


using System;

namespace Lesson02.bt1432
{
    class Program
    {
        static void Main(string[] args)
        {
            Test01();
            Test02();
        }

        static void Test01()
        {
            Employee e1 = new Employee("Tran Van A", "Nam", "HN", "Quan Ly", 2000);
            e1.Display();
        }

        static void Test02()
        {
            Employee e2 = new Employee();
            e2.Input();
            e2.Display();
        }
    }
}


avatar
Hieu Ngo [community,C2009G]
2021-10-07 04:09:32


#Employee.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace People
{
    class Employee
    {
        public string Fullname { get; set; }
        public string Address { get; set; }

        public string Level { get; set; }
        private double _salary;

        public double Salary
        {
            get
            {
                return _salary;
            }
            set
            {
                if(value > 0)
                {
                    this._salary = value;
                } else
                {
                    Console.WriteLine("Salary must be more than 0");
                }
            }
        }
        private string _gender;

        public string Gender
        {
            get
            {
                return _gender;
            }
            set
            {
                if (value == "Male" || value == "Female" || value == "Other")
                {
                    this._gender = value;
                } else
                {
                    Console.WriteLine("Gender error");
                }
            } 
        }
        public Employee() { }
        public Employee(string fullname, string gender, string address, string level, double salary)
        {
            Fullname = fullname;
            Gender = gender;
            Address = address;
            Level = level;
            Salary = salary;
        }

        public void Input()
        {
            Console.WriteLine("Nhap ten:");
            Fullname = Console.ReadLine();
            Console.WriteLine("Nhap gioi tinh(Male/Female/Other):");
            Gender = Console.ReadLine();
            Console.WriteLine("Nhap dia chi:");
            Address = Console.ReadLine();
            Console.WriteLine("Nhap chuc vu:");
            Level = Console.ReadLine();
            Console.WriteLine("Nhap luong:");
            Salary = double.Parse(Console.ReadLine());        
        }

        public void Display()
        {
            Console.WriteLine(this);
        }

        public override string ToString()
        {
            return "Full Name: " + Fullname + ", Gender: " + Gender + ", Address: " + Address + ", Level: " + Level + ", Salary: " + Salary;
        }
    }
}


#Program.cs


using System;

namespace People
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee employee1 = new Employee("Nguyen Van A", "Male", "Ha Noi", "Nhan Vien", 300);
            employee1.Display();
            Employee employee2 = new Employee();
            employee2.Input();
            employee2.Display();
        }
    }
}


avatar
Nguyễn Việt Hoàng [community,AAHN-C2009G]
2021-09-28 16:09:02


#Employee.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss4
{
    class Employee
    {
        private string fullname;
        public string FullName
        {
            get
            {
                return this.fullname;
            }
            set
            {
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.WriteLine("Cannot empty !");
                    Console.WriteLine("Enter FullName :");
                    value = Console.ReadLine();
                }
                this.fullname = value;
            }
        }
        private string gender;
        public string Gender
        {

            get
            {
                return this.gender;
            }
            set
            {

                List<string> valid = new List<string>() { "Male", "Female", "Others" };
                while (!valid.Contains(value, StringComparer.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Gender cannot empty and must be value :(Male or Female or Others) ");
                    Console.WriteLine("Enter Gender :");
                    value = Console.ReadLine();
                }
                this.gender = value;
            }
        }
        private string address;
        public string Address
        {
            get
            {
                return this.address;
            }
            set
            {
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.WriteLine("Cannot empty");
                    Console.WriteLine("Enter Address :");
                    value = Console.ReadLine();
                }
                this.address = value;
            }
        }
        private string office;
        public string Office
        {
            get
            {
                return this.office;
            }
            set
            {
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.WriteLine("Cannot empty");
                    Console.WriteLine("Enter Office :");
                    value = Console.ReadLine();
                }
                this.office = value;
            }
        }
        private double price;
        public double Price
        {
            get
            {
                return this.price;
            }
            set
            {
                while (value <= 0)
                {
                    Console.WriteLine("Price must be > 0 ");
                    Console.WriteLine("Enter Price :");
                    value = int.Parse(Console.ReadLine());

                }
                this.price = value;
            }
        }
        public Employee()
        {

        }
        public Employee(string fullname, string gender, string address, string office, double price)
        {
            this.FullName = fullname;
            this.Gender = gender;
            this.Address = address;
            this.Office = office;
            this.Price = price;
        }
        public void input()
        {
            Console.WriteLine("Enter FullName :");
            FullName = Console.ReadLine();
            Console.WriteLine("Enter Gender (Male or Female or Others) :");
            Gender = Console.ReadLine();
            Console.WriteLine("Enter Address :");
            Address = Console.ReadLine();
            Console.WriteLine("Enter Office :");
            Office = Console.ReadLine();
            Console.WriteLine("Enter Price :");
            string pr = Console.ReadLine();
            while (string.IsNullOrWhiteSpace(pr) || !IsNumeric(pr))
            {
                if (string.IsNullOrWhiteSpace(pr))
                {
                    Console.WriteLine("Cannot empty");
                    Console.WriteLine("Enter Price :");
                }else if (!IsNumeric(pr))
                {
                    Console.WriteLine("Must be number");
                    Console.WriteLine("Enter Price :");
                }
                pr = Console.ReadLine();
            }
            Price = Double.Parse(pr);

        }
        public void display()
        {
            Console.WriteLine("FullName :{0}, Gender :{1}, Address :{2}, Office :{3}, Price :{4}",
                                FullName, Gender, Address, Office, Price);

        }
        static bool IsNumeric(string value)
        {
            try
            {
                double number;
                double.Parse(value); 
            }
            
            catch (Exception ex) { return false; }
            return true;
        }

    }
}


#Program.cs


using System;

namespace Ss4
{
    class Program
    {
        static void Main(string[] args)
        {
            //Employee e = new Employee("Hoang","Nam","HY","Leader",12.90);
            //e.display();
            Employee e = new Employee();
            e.input();
            e.display();
        }
    }
}


avatar
Nguyễn Việt Hoàng [community,AAHN-C2009G]
2021-09-28 16:09:02


#Employee.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss4
{
    class Employee
    {
        private string fullname;
        public string FullName
        {
            get
            {
                return this.fullname;
            }
            set
            {
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.WriteLine("Cannot empty !");
                    Console.WriteLine("Enter FullName :");
                    value = Console.ReadLine();
                }
                this.fullname = value;
            }
        }
        private string gender;
        public string Gender
        {

            get
            {
                return this.gender;
            }
            set
            {

                List<string> valid = new List<string>() { "Male", "Female", "Others" };
                while (!valid.Contains(value, StringComparer.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Gender cannot empty and must be value :(Male or Female or Others) ");
                    Console.WriteLine("Enter Gender :");
                    value = Console.ReadLine();
                }
                this.gender = value;
            }
        }
        private string address;
        public string Address
        {
            get
            {
                return this.address;
            }
            set
            {
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.WriteLine("Cannot empty");
                    Console.WriteLine("Enter Address :");
                    value = Console.ReadLine();
                }
                this.address = value;
            }
        }
        private string office;
        public string Office
        {
            get
            {
                return this.office;
            }
            set
            {
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.WriteLine("Cannot empty");
                    Console.WriteLine("Enter Office :");
                    value = Console.ReadLine();
                }
                this.office = value;
            }
        }
        private double price;
        public double Price
        {
            get
            {
                return this.price;
            }
            set
            {
                while (value <= 0)
                {
                    Console.WriteLine("Price must be > 0 ");
                    Console.WriteLine("Enter Price :");
                    value = int.Parse(Console.ReadLine());

                }
                this.price = value;
            }
        }
        public Employee()
        {

        }
        public Employee(string fullname, string gender, string address, string office, double price)
        {
            this.FullName = fullname;
            this.Gender = gender;
            this.Address = address;
            this.Office = office;
            this.Price = price;
        }
        public void input()
        {
            Console.WriteLine("Enter FullName :");
            FullName = Console.ReadLine();
            Console.WriteLine("Enter Gender (Male or Female or Others) :");
            Gender = Console.ReadLine();
            Console.WriteLine("Enter Address :");
            Address = Console.ReadLine();
            Console.WriteLine("Enter Office :");
            Office = Console.ReadLine();
            Console.WriteLine("Enter Price :");
            string pr = Console.ReadLine();
            while (string.IsNullOrWhiteSpace(pr) || !IsNumeric(pr))
            {
                if (string.IsNullOrWhiteSpace(pr))
                {
                    Console.WriteLine("Cannot empty");
                    Console.WriteLine("Enter Price :");
                }else if (!IsNumeric(pr))
                {
                    Console.WriteLine("Must be number");
                    Console.WriteLine("Enter Price :");
                }
                pr = Console.ReadLine();
            }
            Price = Double.Parse(pr);

        }
        public void display()
        {
            Console.WriteLine("FullName :{0}, Gender :{1}, Address :{2}, Office :{3}, Price :{4}",
                                FullName, Gender, Address, Office, Price);

        }
        static bool IsNumeric(string value)
        {
            try
            {
                double number;
                double.Parse(value); 
            }
            
            catch (Exception ex) { return false; }
            return true;
        }

    }
}


#Program.cs


using System;

namespace Ss4
{
    class Program
    {
        static void Main(string[] args)
        {
            //Employee e = new Employee("Hoang","Nam","HY","Leader",12.90);
            //e.display();
            Employee e = new Employee();
            e.input();
            e.display();
        }
    }
}


avatar
Nguyễn Việt Hoàng [community,AAHN-C2009G]
2021-09-28 16:09:02


#Employee.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss4
{
    class Employee
    {
        private string fullname;
        public string FullName
        {
            get
            {
                return this.fullname;
            }
            set
            {
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.WriteLine("Cannot empty !");
                    Console.WriteLine("Enter FullName :");
                    value = Console.ReadLine();
                }
                this.fullname = value;
            }
        }
        private string gender;
        public string Gender
        {

            get
            {
                return this.gender;
            }
            set
            {

                List<string> valid = new List<string>() { "Male", "Female", "Others" };
                while (!valid.Contains(value, StringComparer.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Gender cannot empty and must be value :(Male or Female or Others) ");
                    Console.WriteLine("Enter Gender :");
                    value = Console.ReadLine();
                }
                this.gender = value;
            }
        }
        private string address;
        public string Address
        {
            get
            {
                return this.address;
            }
            set
            {
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.WriteLine("Cannot empty");
                    Console.WriteLine("Enter Address :");
                    value = Console.ReadLine();
                }
                this.address = value;
            }
        }
        private string office;
        public string Office
        {
            get
            {
                return this.office;
            }
            set
            {
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.WriteLine("Cannot empty");
                    Console.WriteLine("Enter Office :");
                    value = Console.ReadLine();
                }
                this.office = value;
            }
        }
        private double price;
        public double Price
        {
            get
            {
                return this.price;
            }
            set
            {
                while (value <= 0)
                {
                    Console.WriteLine("Price must be > 0 ");
                    Console.WriteLine("Enter Price :");
                    value = int.Parse(Console.ReadLine());

                }
                this.price = value;
            }
        }
        public Employee()
        {

        }
        public Employee(string fullname, string gender, string address, string office, double price)
        {
            this.FullName = fullname;
            this.Gender = gender;
            this.Address = address;
            this.Office = office;
            this.Price = price;
        }
        public void input()
        {
            Console.WriteLine("Enter FullName :");
            FullName = Console.ReadLine();
            Console.WriteLine("Enter Gender (Male or Female or Others) :");
            Gender = Console.ReadLine();
            Console.WriteLine("Enter Address :");
            Address = Console.ReadLine();
            Console.WriteLine("Enter Office :");
            Office = Console.ReadLine();
            Console.WriteLine("Enter Price :");
            string pr = Console.ReadLine();
            while (string.IsNullOrWhiteSpace(pr) || !IsNumeric(pr))
            {
                if (string.IsNullOrWhiteSpace(pr))
                {
                    Console.WriteLine("Cannot empty");
                    Console.WriteLine("Enter Price :");
                }else if (!IsNumeric(pr))
                {
                    Console.WriteLine("Must be number");
                    Console.WriteLine("Enter Price :");
                }
                pr = Console.ReadLine();
            }
            Price = Double.Parse(pr);

        }
        public void display()
        {
            Console.WriteLine("FullName :{0}, Gender :{1}, Address :{2}, Office :{3}, Price :{4}",
                                FullName, Gender, Address, Office, Price);

        }
        static bool IsNumeric(string value)
        {
            try
            {
                double number;
                double.Parse(value); 
            }
            
            catch (Exception ex) { return false; }
            return true;
        }

    }
}


#Program.cs


using System;

namespace Ss4
{
    class Program
    {
        static void Main(string[] args)
        {
            //Employee e = new Employee("Hoang","Nam","HY","Leader",12.90);
            //e.display();
            Employee e = new Employee();
            e.input();
            e.display();
        }
    }
}


avatar
Hoàng Thiện Thanh [community,AAHN-C2009G]
2021-09-28 11:04:36


#Program.cs


using System;

namespace EmployeeManagement
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee e = new Employee();
            e.input();
            e.display();

            Employee e1 = new Employee("Amane", "Female", "Angeles", "The One", 11.222);
            e1.display();
        }
    }
}


#Employee.cs


using System;
using System.Collections.Generic;
using System.Linq;

namespace EmployeeManagement
    {
    public class Employee
    {
        private string name;
        public string Name { get { return name; } 
            set { 
                while (string.IsNullOrEmpty(value)) {
                    Console.WriteLine("Empty Input");
                    value = Console.ReadLine();
                }
                this.name = value;
            }  }
        private string gender;
        public string Gender { get { return gender; } set {
                List<string> g = new List<string> { "Male", "Female", "Other" };
                while (!g.Contains(value, StringComparer.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Input a valid gender.");
                    value = Console.ReadLine();
                }
                this.gender = value;
                } }
        private string address;
        public string Address {
            get { return address; }
            set
            {
                while (string.IsNullOrEmpty(value))
                {
                    Console.WriteLine("Empty Input");
                    value = Console.ReadLine();
                }
                this.address = value;
            }
        }
        private string title;
        public string Title {
            get { return title; }
            set
            {
                while (string.IsNullOrEmpty(value))
                {
                    Console.WriteLine("Empty Input");
                    value = Console.ReadLine();
                }
                this.title = value;
            }
        }
        private double salary;
        public double Salary { get { return salary; } set { this.salary = value; } }
        public Employee()
        {

        }

        public Employee(string Name, string Gender, string Address, string Title, double Salary)
        {
            this.Name = Name;
            this.Gender = Gender;
            this.Address = Address;
            this.Title = Title;
            this.Salary = Salary;
        }

        public void input() {
            Console.WriteLine("Enter employee name: ");
            Name = Console.ReadLine();
            Console.WriteLine("Enter gender: ");
            Gender = Console.ReadLine();
            Console.WriteLine("Enter address: ");
            Address = Console.ReadLine();
            Console.WriteLine("Enter title: ");
            Title = Console.ReadLine();
            Console.WriteLine("Enter salary: ");
            
            string input = Console.ReadLine();
            bool check()
            {
                try { double.Parse(input); } 
                catch (Exception e) { return false; }
                return true;
            }

            while (string.IsNullOrEmpty(input) || check() == false)
            {
                Console.WriteLine("Please input a numeric input");
                input = Console.ReadLine();
            }
            Salary = double.Parse(input);
        }

        public void display()
        {
            Console.WriteLine("Name: {0}\nGender: {1}\nAddress: {2}\nTitle: {3}\nSalary: {4}\n", Name, Gender, Address, Title, Salary);
        }
    }

}


avatar
Triệu Văn Lăng [T2008A]
2021-05-25 09:45:42


#Employee.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace bai1432
{
    class Employee
    {
        public string fullname { get; set; }
        public string gender { get; set; }
        public string address { get; set; }
        public string position { get; set; }
        public double salary { get; set; }

        public Employee() { }

        public Employee(string fullname, string gender, string address, string position, double salary)
        {
            this.fullname = fullname;
            this.gender = gender;
            this.address = address;
            this.position = position;
            this.salary = salary;
        }

        public void input()
        {
            Console.WriteLine("Nhap Ho Ten: ");
            fullname = Console.ReadLine();

            Console.WriteLine("Chon Gioi Tinh: ");
            
            Console.WriteLine("1. Nam");
            Console.WriteLine("2. Nu");
            Console.WriteLine("3. Khong biet");
            int choose = Convert.ToInt32(Console.ReadLine());
            switch (choose)
            {
                case 1:
                    gender = "Nam";
                    break;
                case 2:
                    gender = "Nu";
                    break;
                case 3:
                    gender = "Khong biet";
                    break;
                default:
                    Console.WriteLine("Chon lai!!!");
                    break;
            }

            Console.WriteLine("Nhap Dia chi: ");
            address = Console.ReadLine();

            Console.WriteLine("Nhap chuc vu: ");
            position = Console.ReadLine();

            Console.WriteLine("Nhap Luong( > 0): ");
            salary = double.Parse(Console.ReadLine());
            if(salary < 0)
            {
                Console.WriteLine("Yeu cau nhap luong lon hon 0");
            }
        }

        public void display()
        {
            Console.WriteLine("Ho Ten: {0}, Gioi tinh: {1}, Dia chi: {2}, Chuc vu: {3}, Luong: {4}",
                            fullname, gender, address, position, salary);
        }
    }
}


#Program.cs


using System;

namespace bai1432
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Employee E1 = new Employee("TRAN VAN A", "NAM", "HA NOI", "QUAN LI", 1000000);
            E1.display();

            Employee E2 = new Employee();
            E2.input();
            E2.display();
        }
    }
}


avatar
vuong huu phu [T2008A]
2021-05-22 11:54:52



using System;
using System.Collections.Generic;
using System.Text;

namespace baitap_21_thg_5
{
    class Employee
    {
        public string Hovaten { set; get; }
        public string Gioitinh { set; get; }
        public string Chucvu { set; get; }
        public string Quequan { set; get; }
        public Double Luong { set; get; }

        public Employee()
    {
    }
        public Employee(String Hovaten, String Gioitinh, String Chucvu, String Quequan, Double Luong)
        {
            this.Hovaten = Hovaten;
            this.Gioitinh = Gioitinh;
            this.Chucvu = Chucvu;
            this.Quequan = Quequan;
            this.Luong = Luong;
        }
        public void nhap() {
            Console.WriteLine("Nhap ho va ten: ");
            Hovaten = Console.ReadLine();
            Console.WriteLine("Nhap gioi tinh: ");
            int luachon;
            Console.WriteLine(" 1 Nam ");
            Console.WriteLine(" 2 Nu ");
            Console.WriteLine(" 3 khac ");
            Console.WriteLine("Nhap su lua chon :");
            luachon = Int32.Parse(Console.ReadLine());
            switch (luachon){
                case 1:
                    Gioitinh = " Nam ";
                    break;
                case 2:
                    Gioitinh = " Nu ";
                    break;
                case 3:
                    Gioitinh = " Khac ";
                    break;
                default:
                    Console.WriteLine("Nhap sai");
                    break;
            }
            Console.WriteLine("Nhap chuc vu: ");
            Chucvu = Console.ReadLine();
            Console.WriteLine("Nhap que quan: ");
            Quequan = Console.ReadLine();
            while (Luong <= 0) { 
            Console.WriteLine("Nhap luong (Lon hon 0) = ");
            Luong = Double.Parse(Console.ReadLine());
            }
        }
        public void hienthi() {
            Console.WriteLine("Ten : " + Hovaten + " , Gioitinh = " + Gioitinh + " , Chuc vu = " + Chucvu + " , Que quan = " + Quequan + " , Luong = " + Luong);
        }
    }
}



using System;

namespace baitap_21_thg_5
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee e1 = new Employee();
            e1.nhap();
            e1.hienthi();
            Employee e2 = new Employee("Nguyen van A","Nam","Nhan vien","Ha Noi",2000000);
            e2.hienthi();
        }
    }
}


avatar
Trần Văn Lâm [T2008A]
2021-05-21 14:27:37


#Program.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace les4bt2
{
    class Test
    {
        static Employee emp = new Employee();
        static void Main(string[] args)
        {
            Console.WriteLine("Infor Employee");
            Ob1();
            Ob2();

        }
        public static void Ob1()
        {
            emp.Name = "Tran Van Lam";
            emp.Gender = "Male";
            emp.Address = "Hana";
            emp.Position = "CEO";
            emp.Wage = 999999999999999;
            Console.WriteLine(emp.Name);
            Console.WriteLine(emp.Gender);
            Console.WriteLine(emp.Address);
            Console.WriteLine(emp.Position);
            Console.WriteLine(emp.Wage);
        }
        public static void Ob2()
        {
            emp.Input();
            emp.Display();
        }
        
    }
}


#Employee.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace les4bt2
{
    class Employee
    {
        public string Name { get; set; }
        public string _Gender;
        public string Gender
        {
            get
            {
                return _Gender;
            }
            set
            {
                if (value.Equals("Male") || value.Equals("Female") || value.Equals("Undefined"))
                {
                    this._Gender = value;
                }
                else
                {
                    Console.WriteLine("!!!");
                }
            }
        }
        public string Address { get; set; }
        public string Position { get; set; }
        public double Wage { get; set; }

        public Employee()
        {

        }
        public Employee(string Name, string Gender, string Address, string Position, double Wage )
        {
            this.Name = Name;
            this.Gender = Gender;
            this.Address = Address;
            this.Position = Position;
            this.Wage = Wage;
        }
        public void Input()
        {
            Console.WriteLine("Input Name");
            Name = Console.ReadLine();
            Console.WriteLine("Input Gender:");
            Gender = Console.ReadLine();
            Console.WriteLine("Input Address:");
            Address = Console.ReadLine();                        
            Console.WriteLine("Input Position:");
            Position = Console.ReadLine();
            Console.WriteLine("Input Wage:");
            Wage = Convert.ToDouble(Console.ReadLine());
        }
        public void Display()
        {
            Console.WriteLine("Employe : {0}, {1}, {2}, {3}, {4},", Name, Gender, Address,Position, Wage);
        }
    }
}


avatar
Thành Lâm [T1907A]
2020-06-01 08:09:42



using System;
using System.Text;

namespace Quan_ly_cong_nhan
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.WriteLine("Hello World!");
            Console.WriteLine("====================Quản lý công nhân======================");
            Congnhan();
        }
        static void Congnhan()
        {
            Employee employee = new Employee();
            employee.Fullname = "Nguyễn Thành Lâm";
            employee.Gender = "Nam";

            Console.WriteLine(employee.Fullname);
            Console.WriteLine(employee.Gender);

            employee.input();
            employee.display();
        }

    }
}



using System;
using System.Collections.Generic;
using System.Text;

namespace Quan_ly_cong_nhan
{
    class Employee
    {
        public string Fullname { get; set; }
        private string _gender;
        public string Gender {
            get
            {
                return _gender;
            }
            set
            {
                if(value.Equals("Nam") || value.Equals("Nữ") || value.Equals("không biết"))
                {
                    this._gender = value;
                }
                else
                {
                    Console.WriteLine("Nhập sai giới tính");
                }
            }
        }
        public string Address { get; set; }
        public string Position { get; set; }
        private double _salary;
        public double Salary {
            get
            {
                return _salary;
            }
            set
            {
                if(value > 0)
                {
                    this._salary = value;
                }
                else
                {
                    Console.WriteLine("Lương của bạn phải lớn hơn 0");
                }
            }
        }

        public Employee()
        {

        }

        public void input()
        {
            Console.Write("Nhập tên: ");
            Fullname = Console.ReadLine();
            Console.WriteLine();
            Console.Write("Nhập giới tính: ");
            Gender = Console.ReadLine();
            Console.WriteLine();
            Console.Write("Nhập địa chỉ: ");
            Address = Console.ReadLine();
            Console.WriteLine();
            Console.Write("Nhập chức vụ: ");
            Position = Console.ReadLine();
            Console.WriteLine();
            Console.Write("Nhập lương: ");
            Salary = double.Parse(Console.ReadLine());
            Console.WriteLine();

        }

        public void display ()
        {
            Console.WriteLine("{0},{1},{2},{3},{4}", Fullname, Gender, Address, Position, Salary);
        }

    }
}