-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheCouponCode.cs
50 lines (42 loc) · 2.14 KB
/
TheCouponCode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
namespace ConsoleApp104
{
// Story
// Your online store likes to give out coupons for special occasions.Some customers try to cheat the system by entering invalid codes or using expired coupons.
// Task
// Your mission:
// Write a function called checkCoupon which verifies that a coupon code is valid and not expired.
// A coupon is no more valid on the day AFTER the expiration date. All dates will be passed as strings in this format: "MONTH DATE, YEAR".
// Examples:
// CheckCoupon("123", "123", "July 9, 2015", "July 9, 2015") == true
// CheckCoupon("123", "123", "July 9, 2015", "July 2, 2015") == false
// FUNDAMENTALS, FUNCTIONS, CONTROL FLOW, BASIC LANGUAGE FEATURES, DATES/TIME, STRINGS
public static class Kata
{
public static bool CheckCoupon(string enteredCode, string correctCode, string currentDate, string expirationDate)
{
if (enteredCode == correctCode && DateTime.Parse(currentDate) <= DateTime.Parse(expirationDate))
{
return true;
}
else if (enteredCode == correctCode && DateTime.Parse(currentDate) > DateTime.Parse(expirationDate))
{
return false;
}
return false;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Kata.CheckCoupon("123", "123", "July 9, 2015", "July 9, 2015")); // July 9, 2015 <= July 9, 2015 == true
Console.WriteLine(Kata.CheckCoupon("123", "123", "July 9, 2015", "July 2, 2015")); // July 9, 2015 > July 2, 2015 == false
Console.WriteLine(Kata.CheckCoupon("123", "123", "July 15, 2015", "July 14, 2015")); // July 15, 2015 > July 14, 2015 == false
Console.WriteLine(Kata.CheckCoupon("200", "200", "September 05, 2005", "September 13 2020")); // September 05, 2005 <= September 13, 2020 == true
Console.WriteLine(Kata.CheckCoupon("200", "200", "September 13, 2019", "September 13 2019")); // September 13, 2019 <= September 13, 2019 == true
Console.ReadKey(true);
Console.ReadLine();
}
}
}