Skip to content

Instantly share code, notes, and snippets.

@AzureKitsune
Created December 30, 2016 04:32
Show Gist options
  • Save AzureKitsune/b5318c1857428b735d5c937ed877a0e7 to your computer and use it in GitHub Desktop.
Save AzureKitsune/b5318c1857428b735d5c937ed877a0e7 to your computer and use it in GitHub Desktop.
UWM Parking Garage Fee Calculator
using System;
class MainClass {
public static void Main (string[] args) {
DateTime start = DateTime.Now.Subtract(new TimeSpan(10,0,0)); //example starting time. Take our current time and subtract 10 hours from it.
DateTime end = DateTime.Now; //the current time
Console.WriteLine("Start Time: " + start.ToString());
Console.WriteLine("End Time: " + end.ToString());
Console.WriteLine("Price: $" + GetParkingCost(start, end));
}
public static double GetParkingCost(DateTime startTime, DateTime endTime) {
TimeSpan timeDiff = endTime - startTime;
TimeSpan firstHours;
double cost = 0.0;
//separate the first two hours from the rest of the time
if (timeDiff.Hours < 2) {
firstHours = timeDiff;
timeDiff = new TimeSpan();
} else {
firstHours = new TimeSpan(2,0,0);
timeDiff = timeDiff.Subtract(firstHours);
}
//calculate the initial cost from the first two hours. Rate: $1/30mins
cost = firstHours.TotalMinutes / 30 * 1;
//deal with the remainder time on an hourly basis. Rate: $1/hr
if (timeDiff.TotalHours > 0.0) {
if (startTime.DayOfWeek == DayOfWeek.Sunday) {
cost += timeDiff.TotalHours * 1;
cost = Math.Min(cost, 3);
}
else if (startTime.DayOfWeek == DayOfWeek.Saturday) {
cost += timeDiff.TotalHours * 1;
cost = Math.Min(cost, 5);
}
else {
cost += timeDiff.TotalHours * 1;
cost = Math.Min(cost, 12);
}
}
return Math.Round(cost, 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment