Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class ABE
- {
- static void Main ()
- {
- //
- // ++++CONSTANTS++++
- //
- // 13.5% tax rate.
- const double TAX = 0.135;
- // Power is 13.61 per unit.
- const double POWER = 0.1361;
- // Daily standing charge (DSC) of 41.4 cents.
- const double DSC = 0.41442623;
- // PSO levy of 2.73 per month.
- const double PSOL = 2.73;
- // There's an average of 30.5 days in a given calendar month.
- const double PSOL_TIMER = 30.5;
- // Table format 00 is used at the top. 01 and 02 are for formatting output. 03 is date.
- const string TBL_00 = "{0,-35}{1,10}";
- const string TBL_01 = "{0,-30}{1,-15:#.##}";
- const string TBL_02 = "{0,-30}{1,-15:C}";
- const string TBL_03 = "{0,-30}{1,-15:dd/MM/yyyy}";
- // Today's date.
- DateTime todayDate = DateTime.Now;
- //
- // ++++MOTD++++
- //
- Console.Clear();
- Console.WriteLine("Welcome to Airtricity bill estimator (ABE) v1.0!");
- Console.WriteLine();
- Console.Write("Press any key to begin... ");
- Console.ReadLine();
- //
- // ++++USER INPUT++++
- //
- Console.Clear();
- // Meter readings.
- Console.WriteLine("Meter readings:");
- Console.WriteLine();
- Console.Write(String.Format(TBL_00, "Last billed meter reading:",""));
- double lastRead = Convert.ToDouble(Console.ReadLine());
- Console.Write(String.Format(TBL_00, "Current meter reading:",""));
- double currentRead = Convert.ToDouble(Console.ReadLine());
- // Date of last bill.
- DateTime lastBilled;
- Console.Write(String.Format(TBL_00, "Date of last bill (YYYY-MM-DD):",""));
- lastBilled = Convert.ToDateTime(Console.ReadLine());
- //
- // ++++PROCESSING++++
- //
- // How many days have elapsed since the last bill?
- TimeSpan daysElapsed = todayDate - lastBilled;
- // Convert lastBilled to a double for easy manipulation.
- double daysElapsedDouble = Convert.ToDouble(daysElapsed.TotalDays);
- // How many kilowatts have you used since the last bill?
- double powerUsed = currentRead - lastRead;
- // And how much is that going to cost in practice?
- double billPowerCost = powerUsed * POWER;
- // DSC fee of 0.41442623 a day.
- double billDSCCost = DSC * daysElapsedDouble;
- // PSO levy, charged once per 30 days.
- double billPSOLevy = 0;
- if (daysElapsedDouble >= PSOL_TIMER)
- {
- billPSOLevy = PSOL;
- }
- else if (daysElapsedDouble >= (PSOL_TIMER *2))
- {
- billPSOLevy = PSOL * 2;
- }
- // Tally the subtotal.
- double billSubtotal = billPSOLevy + billDSCCost + billPowerCost;
- // Tax.
- double billTax = billSubtotal * TAX;
- // Total
- double billTotal = billTax + billSubtotal;
- //
- // ++++OUTPUT++++
- //
- Console.Clear();
- Console.WriteLine();
- Console.WriteLine(String.Format(TBL_03, "Date of last bill:", lastBilled));
- Console.WriteLine(String.Format(TBL_03, "Today's date:", todayDate));
- Console.WriteLine(String.Format(TBL_01, "Days since last bill:", daysElapsed.TotalDays));
- Console.WriteLine(String.Format(TBL_01, "------------------------", "-------"));
- Console.WriteLine(String.Format(TBL_01, "Units consumed:", powerUsed));
- Console.WriteLine(String.Format(TBL_02, "Cost per unit:", POWER));
- Console.WriteLine(String.Format(TBL_01, "------------------------", "-------"));
- Console.WriteLine(String.Format(TBL_02, "Power cost:", billPowerCost));
- Console.WriteLine(String.Format(TBL_02, "Daily standing charge:", billDSCCost));
- Console.WriteLine(String.Format(TBL_02, "PSO levy:", billPSOLevy));
- Console.WriteLine();
- Console.WriteLine(String.Format(TBL_02, "Subtotal:", billSubtotal));
- Console.WriteLine(String.Format(TBL_01, "------------------------", "-------"));
- Console.WriteLine(String.Format(TBL_02, "Tax:", billTax));
- Console.WriteLine(String.Format(TBL_02, "Total estimated bill:", billTotal));
- //
- // ++++EOF++++
- //
- Console.WriteLine();
- Console.Write("Press any key to exit... ");
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment