static void Main(string[] args) //DO NOT change the 'Main' method signature { ElectricityBoard bill = new ElectricityBoard(); BillValidator validator = new BillValidator(); Console.WriteLine("Enter Number of Bills To Be Added : "); int noBills = int.Parse(Console.ReadLine()); ElectricityBill[] customer = new ElectricityBill[noBills]; for (int index = 0; index < noBills; index++) { Console.WriteLine("\nEnter Consumer Number:"); string number = Console.ReadLine().ToString(); Regex regex = new Regex(@"EB+[0-9]{5}"); Match match = regex.Match(number); if (!(match.Success)) { throw new FormatException("Invalid Consumer Number"); } Console.WriteLine("Enter Consumer Name:"); string name = Console.ReadLine().ToString(); int units = 0; while (true) { Console.WriteLine("Enter Units Consumed:"); units = int.Parse(Console.ReadLine()); if (validator.ValidateUnitsConsumed(units) == "1") { break; } } double amount = 0; customer[index] = new ElectricityBill(name, number, units, amount); bill.CalculateBill(customer[index]); bill.AddBill(customer[index]); } Console.WriteLine("Enter Last 'N' Number of Bills To Generate:"); noBills = int.Parse(Console.ReadLine()); for (int index = 0; index < noBills; index++) { Console.WriteLine("{0}", customer[index].ConsumerName); Console.WriteLine("{0}", customer[index].ConsumerNumber); Console.WriteLine("{0}", customer[index].UnitsConsumed); Console.WriteLine("{0}", customer[index].BillAmount); } Console.WriteLine("Details of last ‘N’ bills:"); List <ElectricityBill> dbPrint = bill.Generate_N_BillDetails(noBills); foreach (ElectricityBill item in dbPrint) { Console.WriteLine("EB Bill for {0} is {1}", item.ConsumerName, item.BillAmount); } }
static void Main(string[] args) //DO NOT change the 'Main' method signature { BillValidator billValidator = new BillValidator(); ElectricityBoard electricityBoard = new ElectricityBoard(); List <ElectricityBill> tempDisplayList = new List <ElectricityBill>(); Console.WriteLine("Enter Number of Bills To Be Added:"); int numberOfBills = int.Parse(Console.ReadLine()); for (int i = 1; i <= numberOfBills; i++) { Console.WriteLine("Enter Consumer Number:"); string consumerNumber = Console.ReadLine(); if (Regex.IsMatch(consumerNumber, "EB[0-9]{5}") == false) { throw new FormatException("Invalid Consumer Number"); } Console.WriteLine("Enter Consumer Name:"); string consumerName = Console.ReadLine(); Console.WriteLine("Enter Units Consumed:"); int unitsConsumed = int.Parse(Console.ReadLine()); while (billValidator.ValidateUnitsConsumed(unitsConsumed) != "") { Console.WriteLine(billValidator.ValidateUnitsConsumed(unitsConsumed)); Console.WriteLine("Enter Units Consumed:"); unitsConsumed = int.Parse(Console.ReadLine()); } ElectricityBill electricityBill = new ElectricityBill(consumerNumber, consumerName, unitsConsumed); electricityBoard.CalculateBill(electricityBill); tempDisplayList.Add(electricityBill); electricityBoard.AddBill(electricityBill); } Console.WriteLine("Enter Last 'N' Number of Bills to Generate"); int numberofBillsToGenerate = int.Parse(Console.ReadLine()); foreach (ElectricityBill bill in tempDisplayList) { Console.WriteLine(bill.ConsumerNumber); Console.WriteLine(bill.ConsumerName); Console.WriteLine(bill.UnitsConsumed); Console.WriteLine("Bill Amount:" + bill.BillAmount); Console.WriteLine(""); } List <ElectricityBill> dislpaylist = electricityBoard.Generate_N_BillDetails(numberofBillsToGenerate); Console.WriteLine("Details of last 'N' bills:"); foreach (ElectricityBill bill in dislpaylist) { Console.WriteLine("EB Bill for " + bill.ConsumerName + " is " + bill.BillAmount); } Console.ReadKey(); }
static void Main(string[] args) { try { //Implement the code here Console.WriteLine("Enter Number of Bills To Be Added : "); int number = int.Parse(Console.ReadLine()); string conNumber = String.Empty; string conName = String.Empty; int unitsCon; string pattern = "^EB[0-9]{5}$"; BillValidator billValidator = new BillValidator(); for (int i = 0; i < number; i++) { Console.WriteLine("Enter Consumer Number:"); conNumber = Console.ReadLine(); if (!Regex.IsMatch(conNumber, pattern)) { throw new FormatException("Invalid Consumer Number"); } Console.WriteLine("Enter Consumer Name:"); conName = Console.ReadLine(); Console.WriteLine("Enter Units Consumed:"); unitsCon = int.Parse(Console.ReadLine()); while (billValidator.ValidateUnitsConsumed(unitsCon) == "Given units is invalid") { Console.WriteLine("Given units is invalid"); Console.WriteLine("Enter Units Consumed:"); unitsCon = int.Parse(Console.ReadLine()); } ElectricityBill bill = new ElectricityBill(conNumber, conName, unitsCon, 0); ElectricityBoard board = new ElectricityBoard(); board.CalculateBill(bill); board.AddBill(bill); } Console.WriteLine("Enter Last 'N' Number of Bills To Generate:"); int num = int.Parse(Console.ReadLine()); ElectricityBoard electricityBoard = new ElectricityBoard(); List <ElectricityBill> electricityBills = electricityBoard.Generate_N_BillDetails(num); foreach (ElectricityBill bill in electricityBills) { Console.WriteLine(bill); } foreach (ElectricityBill bill in electricityBills) { Console.WriteLine($"EB Bill for {bill.ConsumerName} is {bill.BillAmount}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) //DO NOT change the 'Main' method signature { //Implement the code here ElectricityBoard eb = null; DBHandler db = new DBHandler(); int noOfBills; List <ElectricityBill> li = new List <ElectricityBill>(); Console.WriteLine("Enter Number of Bills To Be Added :"); noOfBills = int.Parse(Console.ReadLine()); BillValidator b = new BillValidator(); for (int i = 0; i < noOfBills; i++) { string consumerNumber, consumerName; int units; Console.WriteLine("Enter Consumer Number:"); consumerNumber = Console.ReadLine(); Console.WriteLine("Enter Consumer Name:"); consumerName = Console.ReadLine(); do { Console.WriteLine("Enter Units Consumed:"); units = int.Parse(Console.ReadLine()); Console.WriteLine(b.ValidateUnitsConsumed(units)); } while (b.ValidateUnitsConsumed(units) != null); ElectricityBill ebill = new ElectricityBill(); try { ebill.ConsumerNumber = consumerNumber; ebill.ConsumerName = consumerName; ebill.UnitsConsumed = units; } catch (FormatException) { Console.WriteLine("Invalid Consumer Number"); continue; } eb = new ElectricityBoard(); eb.CalculateBill(ebill); eb.SqlCon = db.GetConnection(); eb.AddBill(ebill); li.Add(ebill); } eb.SqlCon = db.GetConnection(); Console.WriteLine(); Console.WriteLine(); foreach (var bill in li) { Console.WriteLine(bill.ConsumerName); Console.WriteLine(bill.ConsumerNumber); Console.WriteLine(bill.UnitsConsumed); Console.WriteLine("Bill Amount:" + bill.BillAmount); } Console.WriteLine("Enter Last 'N' Number of Bills To Generate:"); int num = int.Parse(Console.ReadLine()); List <ElectricityBill> li2 = eb.Generate_N_BillDetails(num); Console.WriteLine("Details of last ‘N’ bills:"); foreach (var j in li2) { Console.WriteLine("EB Bill for " + j.ConsumerName + " is " + j.BillAmount); } Console.ReadKey(); }