Example #1
0
        static void Main(string[] args)
        {
            BillValidator   bb    = new BillValidator();
            ElectricityBill ebill = new ElectricityBill();

            bb.ValidateUnitsConsumed(ebill.UnitsConsumed);
            Console.WriteLine("Enter Number of Bills To Be Added :");
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                // ElectricityBill ebill = new ElectricityBill();
                Console.WriteLine("Enter Consumer Number:");
                string c = Console.ReadLine();
                try
                {
                    string temp = @"^[E][B][0-9]{5}$";
                    Regex  R    = new Regex(temp);
                    if (!R.IsMatch(c))
                    {
                        throw new Exception("Invalid Consumer Number");
                    }
                    else
                    {
                        ebill.ConsumerNumber = c;
                        Console.WriteLine("Enter Consumer Name:");
                        string s = Console.ReadLine();
                        ebill.ConsumerName = s;
                        Console.WriteLine("Enter Units Consumed:");
                        int u = int.Parse(Console.ReadLine());
                        ebill.UnitsConsumed = u;
                    }
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            Console.WriteLine("Enter Last 'N' Number of Bills To Generate");
            int num             = int.Parse(Console.ReadLine());
            ElectricityBoard eb = new ElectricityBoard();

            eb.CalculateBill(ebill);
            eb.AddBill(ebill);

            List <ElectricityBill> El = eb.Generate_N_BillDetails(num);
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Number of bills to be added");
            int    n = int.Parse(Console.ReadLine());
            string number;
            string name;
            int    units;

            ElectricityBill[] ebill     = new ElectricityBill[n];
            BillValidator     bvalidate = new BillValidator();
            ElectricityBoard  eboard    = new ElectricityBoard();

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine();
                ebill[i] = new ElectricityBill();
                try
                {
                    Console.WriteLine("Enter Consumer Number:");
                    number = Console.ReadLine();

                    string p = @"^[E][B][0-9]{5}$";
                    Regex  r = new Regex(p);
                    if (r.IsMatch(number))
                    {
                        ebill[i].ConsumerNumber = number;
                        Console.WriteLine("Enter Consumer Name:");
                        name = Console.ReadLine();

                        ebill[i].ConsumerName = name;
                        Console.WriteLine("Enter Units Consumed:");
                        units = int.Parse(Console.ReadLine());
                        while (bvalidate.ValidateUnitsConsumed(units) != null)
                        {
                            Console.WriteLine(bvalidate.ValidateUnitsConsumed(units));
                            Console.WriteLine("Enter Units Consumed:");
                            units = int.Parse(Console.ReadLine());
                        }

                        ebill[i].UnitsConsumed = units;

                        //Console.WriteLine(ebill[i].ConsumerNumber);
                        eboard.AddBill(ebill[i]);
                    }

                    else
                    {
                        throw new FormatException("Invalid Consumer Number");
                    }
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            Console.WriteLine();


            Console.WriteLine("Enter Last 'N' Number of Bills To Generate");
            int num = int.Parse(Console.ReadLine());
            List <ElectricityBill> list = eboard.Generate_N_BillDetails(num);

            Console.WriteLine();
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(ebill[i].ConsumerNumber + "\n" + ebill[i].ConsumerName
                                  + "\n" + ebill[i].UnitsConsumed + "\n" + ebill[i].BillAmount);
                Console.WriteLine();
            }
            Console.WriteLine("Details of last ā€˜Nā€™ bills:");
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("EB bill for " + list[i].ConsumerName + " is " + list[i].BillAmount);
            }
            Console.Read();
        }