forked from mahays0/CSSE376Lab2-UnitTesting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlight.cs
53 lines (42 loc) · 1.17 KB
/
Flight.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
51
52
53
using System;
namespace Expedia
{
public class Flight : Booking
{
private DateTime dateThatFlightLeaves;
private DateTime dateThatFlightReturns;
public int Miles
{
get; private set;
}
#region Booking implementation
public double getBasePrice ()
{
var lengthOfSpread = (dateThatFlightReturns - dateThatFlightLeaves).Days;
return 200 + lengthOfSpread*20;
}
#endregion
public Flight (DateTime startDate, DateTime endDate, int someMiles)
{
if(endDate < startDate)
throw new InvalidOperationException("End date cannot be before start date!");
if(someMiles < 0)
throw new ArgumentOutOfRangeException("Miles must be positive!");
dateThatFlightLeaves = startDate;
dateThatFlightReturns = endDate;
Miles = someMiles;
}
public override bool Equals(object obj) {
if(obj is Flight) {
return Equals(obj as Flight);
}
return base.Equals(obj);
}
private bool Equals(Flight obj) {
bool l = obj.dateThatFlightLeaves.Equals(this.dateThatFlightLeaves);
bool r = obj.dateThatFlightReturns.Equals(this.dateThatFlightReturns);
bool m = obj.Miles.Equals(this.Miles);
return l && r && m;
}
}
}