bhalash

ABE v1.0

Jan 27th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.00 KB | None | 0 0
  1. using System;
  2.  
  3. public class ABE
  4. {
  5.     static void Main ()
  6.     {
  7.         //
  8.        
  9.         // ++++CONSTANTS++++
  10.        
  11.         //
  12.        
  13.         // 13.5% tax rate.
  14.         const double TAX = 0.135;
  15.        
  16.         // Power is 13.61 per unit.
  17.         const double POWER = 0.1361;
  18.        
  19.         // Daily standing charge (DSC) of 41.4 cents.
  20.         const double DSC = 0.41442623;
  21.        
  22.         // PSO levy of 2.73 per month.
  23.         const double PSOL = 2.73;
  24.        
  25.         // There's an average of 30.5 days in a given calendar month.
  26.         const double PSOL_TIMER = 30.5;
  27.        
  28.         // Table format 00 is used at the top. 01 and 02 are for formatting output. 03 is date.
  29.         const string TBL_00 = "{0,-35}{1,10}";
  30.         const string TBL_01 = "{0,-30}{1,-15:#.##}";
  31.         const string TBL_02 = "{0,-30}{1,-15:C}";
  32.         const string TBL_03 = "{0,-30}{1,-15:dd/MM/yyyy}";
  33.        
  34.         // Today's date.
  35.         DateTime todayDate = DateTime.Now;
  36.        
  37.         //
  38.        
  39.         // ++++MOTD++++
  40.        
  41.         //
  42.        
  43.         Console.Clear();
  44.        
  45.         Console.WriteLine("Welcome to Airtricity bill estimator (ABE) v1.0!");
  46.         Console.WriteLine();
  47.         Console.Write("Press any key to begin... ");
  48.         Console.ReadLine();
  49.        
  50.         //
  51.        
  52.         // ++++USER INPUT++++
  53.        
  54.         //
  55.        
  56.         Console.Clear();
  57.        
  58.         // Meter readings. 
  59.         Console.WriteLine("Meter readings:");
  60.         Console.WriteLine();
  61.  
  62.         Console.Write(String.Format(TBL_00, "Last billed meter reading:",""));
  63.         double lastRead = Convert.ToDouble(Console.ReadLine());
  64.        
  65.         Console.Write(String.Format(TBL_00, "Current meter reading:",""));
  66.         double currentRead = Convert.ToDouble(Console.ReadLine());
  67.        
  68.         // Date of last bill.
  69.         DateTime lastBilled;
  70.         Console.Write(String.Format(TBL_00, "Date of last bill (YYYY-MM-DD):",""));
  71.         lastBilled = Convert.ToDateTime(Console.ReadLine());
  72.            
  73.         //
  74.        
  75.         // ++++PROCESSING++++
  76.        
  77.         //
  78.        
  79.         // How many days have elapsed since the last bill?
  80.         TimeSpan daysElapsed = todayDate - lastBilled;
  81.  
  82.         // Convert lastBilled to a double for easy manipulation.
  83.         double daysElapsedDouble = Convert.ToDouble(daysElapsed.TotalDays);
  84.        
  85.         // How many kilowatts have you used since the last bill?
  86.         double powerUsed = currentRead - lastRead;
  87.        
  88.         // And how much is that going to cost in practice?
  89.         double billPowerCost = powerUsed * POWER;
  90.        
  91.         // DSC fee of 0.41442623 a day.
  92.         double billDSCCost = DSC * daysElapsedDouble;
  93.        
  94.         // PSO levy, charged once per 30 days.
  95.         double billPSOLevy = 0;
  96.         if  (daysElapsedDouble >= PSOL_TIMER)
  97.         {
  98.             billPSOLevy = PSOL;
  99.         }
  100.         else if (daysElapsedDouble >= (PSOL_TIMER *2))
  101.         {
  102.             billPSOLevy = PSOL * 2;
  103.         }
  104.        
  105.         // Tally the subtotal.
  106.         double billSubtotal = billPSOLevy + billDSCCost + billPowerCost;
  107.        
  108.         // Tax.
  109.         double billTax = billSubtotal * TAX;
  110.        
  111.         // Total
  112.         double billTotal = billTax + billSubtotal;
  113.        
  114.         //
  115.        
  116.         // ++++OUTPUT++++
  117.        
  118.         //
  119.        
  120.         Console.Clear();
  121.        
  122.         Console.WriteLine();   
  123.         Console.WriteLine(String.Format(TBL_03, "Date of last bill:", lastBilled));
  124.         Console.WriteLine(String.Format(TBL_03, "Today's date:", todayDate));
  125.         Console.WriteLine(String.Format(TBL_01, "Days since last bill:", daysElapsed.TotalDays));
  126.         Console.WriteLine(String.Format(TBL_01, "------------------------", "-------"));
  127.         Console.WriteLine(String.Format(TBL_01, "Units consumed:", powerUsed));
  128.         Console.WriteLine(String.Format(TBL_02, "Cost per unit:", POWER));
  129.         Console.WriteLine(String.Format(TBL_01, "------------------------", "-------"));
  130.         Console.WriteLine(String.Format(TBL_02, "Power cost:", billPowerCost));
  131.         Console.WriteLine(String.Format(TBL_02, "Daily standing charge:", billDSCCost));
  132.         Console.WriteLine(String.Format(TBL_02, "PSO levy:", billPSOLevy));
  133.         Console.WriteLine();
  134.         Console.WriteLine(String.Format(TBL_02, "Subtotal:", billSubtotal));
  135.         Console.WriteLine(String.Format(TBL_01, "------------------------", "-------"));
  136.         Console.WriteLine(String.Format(TBL_02, "Tax:", billTax));
  137.         Console.WriteLine(String.Format(TBL_02, "Total estimated bill:", billTotal));
  138.        
  139.         //
  140.        
  141.         // ++++EOF++++
  142.        
  143.         //
  144.            
  145.         Console.WriteLine();
  146.         Console.Write("Press any key to exit... ");
  147.         Console.ReadLine();
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment