Lập hóa đơn tiền điện nước như thế nào cho logic?

em khai báo sai , thiếu những thuộc tính và điều kiện gì ạ
mong anh/chị giúp em viết phần tính giá tiền điện , tiền nước và tổng tiền với ạ

 namespace QuanLytiendiennuoccuasinhvienokitucxa
{
    class hoadon
    {
        {
        private string maPhong;
        private DateTime thang;
        int mm, yyyy, chisoDiencu , chisoDienmoi ,chisoNuoccu , chisoNuocmoi;


        public DateTime Thang { get => thang; set => thang = value; }
        public string MaPhong { get => maPhong; set => maPhong = value; }
        public int ChisoDiencu { get => chisoDiencu ; set => chisoDiencu = value; }
        public int ChisoDienmoi { get => chisoDienmoi; set => chisoDienmoi = value; }
        public int ChisoNuocmoi { get => chisoDienmoi; set => chisoDienmoi = value; }
        public int ChisoNuoccu { get => chisoNuoccu; set => chisoNuoccu = value; }


        public hoadon() { }
        public hoadon(DateTime thang, string maPhong, int chisoDiencu, int chisoDienmoi , int chisoNuoccu , int chisoNuocmoi)
        {
            this.Thang = thang;
            this.MaPhong = maPhong;
            this.ChisoDienmoi = chisoDienmoi;
            this.ChisoDiencu = chisoDiencu;
            this.ChisoNuoccu = chisoNuoccu;
            this.ChisoNuocmoi = chisoNuocmoi;

        }
        public void Nhap()
        {
            
            do
            {
                Console.Write("\n\t\t\t\t\t\t Nhập mã phòng:");
                MaPhong = Console.ReadLine();
                if (MaPhong.Length == 0)
                {
                    Console.WriteLine("\t\t\t\t\t\t Mời nhập lại.....!!!");
                }
            } while (MaPhong.Length == 0);
            do
            {
                try
                {
                    do
                    {
                        Console.Write("\t\t\t\t\t\t Nhập tháng  :");
                        mm = int.Parse(Console.ReadLine());
                        if (!(mm >= 1 && mm <= 12))
                        {
                            Console.WriteLine("\t\t\t\t\t\t Mời nhập lại.......!!!");
                        }
                    } while (!(mm >= 1 && mm <= 12));
                    break;
                }
                catch (Exception e)
                {
                    Console.Write("\t\t\t\t\t\t");
                    Console.WriteLine(e.Message);
                    Console.WriteLine("\t\t\t\t\t\t Mời nhập lại.......!!!");
                }
            } while (true);
            do
            {
                try
                {
                    do
                    {
                        Console.Write("\t\t\t\t\t\t Nhập năm sinh :");
                        yyyy = int.Parse(Console.ReadLine());
                        if (!(yyyy >= 1900 && yyyy <= 2099))
                        {
                            Console.WriteLine("\t\t\t\t\t\tMời nhập lại.......!!!");
                        }
                    } while (!(yyyy >= 1900 && yyyy <= 2099));
                    break;
                }
                catch (Exception e)
                {
                    Console.Write("\t\t\t\t\t\t");
                    Console.WriteLine(e.Message);
                    Console.WriteLine("\t\t\t\t\t\t Mời nhập lại.......!!!");
                }
            } while (true);
            Thang = new DateTime ( month: mm, year: yyyy);
            do
            {
                Console.Write("\n\t\t\t\t\t\t Nhập chỉ số điện cũ ");
                ChisoDiencu = int.Parse(Console.ReadLine());
                if (ChisoDiencu.Length == 0)
                {
                    Console.WriteLine("\t\t\t\t\t\t Mời nhập lại.....!!!");
                }
            } while (ChisoDiencu.Length == 0);
            do
            {
                Console.Write("\n\t\t\t\t\t\t Nhập chỉ số điện mới ");
                ChisoDiencu = int.Parse(Console.ReadLine());
                if (ChisoDiencu.Length == 0)
                {
                    Console.WriteLine("\t\t\t\t\t\t Mời nhập lại.....!!!");
                }
            } while (ChisoDiencu.Length == 0);
            do
            {
                Console.Write("\n\t\t\t\t\t\t Nhập chỉ số nước cũ ");
                ChisoDiencu = int.Parse(Console.ReadLine());
                if (ChisoNuoccu.Length == 0)
                {
                    Console.WriteLine("\t\t\t\t\t\t Mời nhập lại.....!!!");
                }
            } while (ChisoNuoccu.Length == 0);
            do
            {
                Console.Write("\n\t\t\t\t\t\t Nhập chỉ số nước mới ");
                ChisoNuocmoi = int.Parse(Console.ReadLine());
                if (Chisonuocmoi.Length == 0)
                {
                    Console.WriteLine("\t\t\t\t\t\t Mời nhập lại.....!!!");
                }
            } while (ChisoNuocmoi.Length == 0);
        }
}

Tính toán thì có gì mà khó dữ vậy? Chỉ là các phép +, -, *, / cơ bản thôi mà!
Phần nhập thì những gì giống nhau có thể gom thành 1 phương thức (với tham số và kiểu trả về tương ứng).
Phần lặp do - while chỉ cần 1 vòng lặp là được.

Phải có giá trên mỗi đơn vị (điện, nước) thì mới tính tiền được. Còn giá thuê phòng mỗi tháng nữa. Những thứ này nên gán ở hàm dựng.

5 Likes

dạ em xin trân thành cảm ơn ạ

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?