By GokiSoft.com| 17:26 29/10/2021|
C Sharp

Ôn tập OOP - Table - Trong C# - Lập Trình C# - Lập Trình C Sharp

Tạo một lớp đối tượng Table trong namespace đặt tên là room -> gồm các thuộc tính sau

- Tên, màu sắc, nhà sản xuất, số ngày đã sử dụng

Yêu cầu :

Tạo ra 2 hàm tạo : ham tạo ko đối và hàm tạo có đầy đủ đối số

Tạo ra get/set cho các thuộc tính trên

Tạo ra hàm nhập và hiển thị thông tin cho table.

Viết chương trình test chức năng nhập và hiển thị

Viết chương trình test -> tạo ra 2 đối tượng table với 2 hàm tạo khác nhau -> Hiên thị thông tin của chúng

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Do Trung Duc [T2008A]
Do Trung Duc

2021-05-17 14:53:28



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

namespace Lesson2.room
{
    public class Table
 {
        public string Name { get; set; }
       public  string Color { get; set; }
        public string Manufacture { get; set; }

        int _UsedDay;
        public int UsedDay
        {
            get
            {
                return _UsedDay;
            }
            set
            {
                if (value <= 0)
                {
                    Console.WriteLine("Price khong duoc phep am!!!");
                }
                else
                {
                    _UsedDay = value;
                }
            }
        }

        public Table() {
        }

        public Table(string Name, string Color, string Manufacture, int UsedDay)
        {
            this.Name = Name;
            this.Color = Color;
            this.Manufacture = Manufacture;
            this.UsedDay = UsedDay;
        }

        public void Display()
        {
            Console.WriteLine("name:" + Name);
            Console.WriteLine("mau:" + Color);
            Console.WriteLine("nha sx:" + Manufacture);
            Console.WriteLine("ngay da su dung:" + UsedDay);
        }

        public void Input()
        {
            Console.WriteLine("Nhap ten:" );
            Name = Console.ReadLine();
            Console.WriteLine("mau:" + Color);
            Color = Console.ReadLine();
            Console.WriteLine("nha sx:" + Manufacture);
            Manufacture = Console.ReadLine();
            Console.WriteLine("ngay da su dung:" + UsedDay);
            UsedDay = Int32.Parse(Console.ReadLine());
        }




    }
}



Do Trung Duc [T2008A]
Do Trung Duc

2021-05-17 14:53:13



using System;
using Lesson2.room;

namespace Lesson2
{
    class Program
    {
        static void Main(string[] args)
        {
            Table table1 = new Table();
            table1.Name = "Bang nhap nhap";
            table1.Color = "Black";
            table1.Manufacture = "American";
            table1.UsedDay = 10;

            Table table2 = new Table("Bang noi dia","White","Vietnam",100);

            Table table3 = new Table();
            table3.Input();

            table1.Display();
            table2.Display();
            table3.Display();
        }
    }
}



hainguyen [T2008A]
hainguyen

2021-05-17 10:07:40



using System;

namespace room
{
    class Test
    {
        static void Main(string[] args)
        {
            Table table1 = new Table();
            Table table2 = new Table();

            table1.input();
            table2.input();

            table1.display();
            table2.display();
        }

    }
}



hainguyen [T2008A]
hainguyen

2021-05-17 10:07:22



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

namespace room
{
    class Table
    {
        public string ten { get; set; }
        public string color { get; set; }
        public string nxb { get; set; }
        public int nsd { get; set; }

        public Table() { }

        public Table(string ten, string color, string nxb, int nsd)
        {
            this.ten = ten;
            this.color = color;
            this.nxb = nxb;
            this.nsd = nsd;
        }

        public void input()
        {
            Console.WriteLine("Nhap ten: ");
            ten = Console.ReadLine();

            Console.WriteLine("Nhap color: ");
            color = Console.ReadLine();

            Console.WriteLine("Nhap nxb: ");
            nxb = Console.ReadLine();

            Console.WriteLine("Nhap nsd: ");
            nsd = Convert.ToInt32(Console.ReadLine());
        }

        public void display()
        {
            Console.WriteLine("ten: = {0}, color: = {1}, nxb: = {2}, nsd: = {3}", ten, color, nxb, nsd);
        }
        
    }
}



Trần Văn Lâm [T2008A]
Trần Văn Lâm

2021-05-17 09:10:27


#Table.cs


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

namespace room
{
    class Table
    {
        public string Name { get; set; }
        public string Color { get; set; }
        public string Menufacture { get; set; }
        public int Day { get; set; }
        public Table()
        {

        }
        public Table(string Name, string Color, string Menufacture, int Day)
        {
            this.Name = Name;
            this.Color = Color;
            this.Menufacture = Menufacture;
            this.Day = Day;
        }
        public void Input()
        {
            Console.WriteLine("Nhap ten:");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap mau sac:");
            Color = Console.ReadLine();
            Console.WriteLine("Nhap ten nha san xuat:");
            Menufacture = Console.ReadLine();
            Console.WriteLine("Nhap so ngay da su dung:");
            Day = Convert.ToInt32(Console.ReadLine());
        }
        public void Display()
        {
            Console.WriteLine(" {0} , {1} , {2} ,{3}", Name, Color, Menufacture, Day);
        }

 
    }
}



Trần Văn Lâm [T2008A]
Trần Văn Lâm

2021-05-17 09:10:08


#Program.cs


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

namespace room
{
    class Program
    {
        static void Main(string[] args)
        {
            Table tb = new Table();
            tb.Input();
            tb.Display();
        }
    }
}



Nguyễn Tiến Đạt [T2008A]
Nguyễn Tiến Đạt

2021-05-17 08:59:51


#Table.cs


using System;

namespace room
{
    class Table
    {
        public string Name { get; set; }
        public string Color { get; set; }
        public string Manu { get; set; }
        public int UsedDate { get; set; }
        public Table()
        {

        }
        public Table(string Name, string Color, string Manu, int UsedDate)
        {
            this.Name = Name;
            this.Color = Color;
            this.Manu = Manu;
            this.UsedDate = UsedDate;
        }

    }
}


#Test.cs


using System;
using room;
namespace test
{
    class Test
    {
        static void Main(string[] args)
        {
            Table table1 = new Table();
            table1.Name = "Ban tron";
            table1.Color = "Vang";
            table1.Manu = "ABC";
            table1.UsedDate = 25;
            Table table2 = new Table("Ban go", "Do", "CDE",30);
            Console.WriteLine("Ban 1: {0}, {1}, {2}, {3}",table1.Name,table1.Color,table1.Manu,table1.UsedDate);
            Console.WriteLine("Ban 2: {0}, {1}, {2}, {3}", table2.Name, table2.Color, table2.Manu, table2.UsedDate);
        }
    }
}



vuong huu phu [T2008A]
vuong huu phu

2021-05-17 08:49:09



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

namespace quanlisanpham
{
   public class Table
    {
        String Ten;
        String Mausac;
        String Nhasanxuat;
        int Songaysudung;

        public Table(String Ten, String Mausac, String Nhasanxuat, int Songaysudung)
        {
            this.Ten = Ten;
            this.Mausac = Mausac;
            this.Nhasanxuat = Nhasanxuat;
            this.Songaysudung = Songaysudung;

        }

        public Table() { 
        }

        public String _Ten { get; set; }
        public String _Mausac { get; set; }
        public String _Nhasanxuat { get; set; }
        public int _Songaysudung { get; set; }

        public void Nhap()
        {
            Console.WriteLine("Nhaop ten san pham: ");
            Ten = Console.ReadLine();
            Console.WriteLine("Nhap mau sac: ");
            Mausac = Console.ReadLine();
            Console.WriteLine("Nhap nha san xuat: ");
            Nhasanxuat = Console.ReadLine();
            Console.WriteLine("Nhap so ngay su dung: ");
            Songaysudung = Int32.Parse(Console.ReadLine());
        }

        public void Hienthi()
        {
            Console.WriteLine("Ten san pham : " + Ten);
            Console.WriteLine("Mau sac san pham : " + Mausac);
            Console.WriteLine("Nha San xuat : " + Nhasanxuat);
            Console.WriteLine("So ngay su dung : " + Songaysudung);
        }
    }
}



using System;

namespace quanlisanpham
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("table 1 :");
            Table tb1 = new Table();
            tb1.Nhap();
            tb1.Hienthi();
            Console.WriteLine("table 2 :");
            Table tb2 = new Table("San pham a", "do","Nha san xuat a",20) ;
            tb2.Hienthi();
        }
    }
}



Luong Dinh Dai [T1907A]
Luong Dinh Dai

2020-06-04 08:48:32


#Table.cs


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

namespace BTOOP
{
    class Table
    {
        public string NameTable { get; set; }
        public string Color { get; set; }
        public int NumberofDaysUsed { get; set; }

        public Table() { }
        public Table(string nametable, string color, int numberofDaysUsed)
        {
            NameTable = nametable;
            Color = color;
            NumberofDaysUsed = numberofDaysUsed;
        }
        public void input()
        {
            Console.WriteLine("input nametable ");
            NameTable = Console.ReadLine();
            Console.WriteLine("input color");
            Color = Console.ReadLine();
            Console.WriteLine("input numberofDaysUserd ");
            NumberofDaysUsed = Convert.ToInt32(Console.ReadLine());
        }
        public void display()
        {
            Console.WriteLine("NameTable ={0}, Color={1},NumberofDaysUsed ={2}", NameTable, Color, NumberofDaysUsed);
        }
    }
}


#Program.cs


using System;

namespace BTOOP
{
    class Program
    {
        static void Main(string[] args)
        {
            Table tb = new Table();
            tb.input();
            tb.display();
            Table tb1 = new Table("table2", "white", 5);
            tb1.display();
        }
    }
}



Minh Nghia [T1907A]
Minh Nghia

2020-05-30 07:11:17



using System;

namespace Room
{
    class Program
    {
        static void Main(string[] args)
        {
            Table table1 = new Table();
            Table table2 = new Table("BMW","Black","Nghia", 4 );

            table1.Input();
            table1.Display();
            table2.Display();
        }
    }
}



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

namespace Room
{
    class Table
    {
        public string Name { get; set; }
        public string Color { get; set; }
        public string Producer { get; set; }
        public int numberDayUser { get; set; }

        public Table() { }

        public Table(string Name, string Color,string Producer, int numberDayUser)
        {
            this.Name = Name;
            this.Color = Color;
            this.Producer = Producer;
            this.numberDayUser = numberDayUser;
        }

        public void Input()
        {
            Console.WriteLine("Enter name :");
            Name = Console.ReadLine();
            Console.WriteLine("Enter color :");
            Color = Console.ReadLine();
            Console.WriteLine("Enter producer :");
            Producer = Console.ReadLine();
            Console.WriteLine("Enter number day user :");
            numberDayUser = int.Parse(Console.ReadLine());
        }
        public void Display()
        {
            Console.WriteLine("Name : {0}, Color : {1}, Producer :{2}, NumberDay :{3}", Name, Color, Producer, numberDayUser);
        }
    }
}