-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVaccinationRecords.cs
113 lines (103 loc) · 3.83 KB
/
VaccinationRecords.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cortez_Adrian_Lab2
{
internal class VaccinationRecords
{
private string vacKey = "";
private string vacDate = "";
private string vacPerson = "";
// properties so that we can access the private fields
public string VacKey
{
get { return vacKey; }
set {
// determine if length of value is exactly 4 characters long
if (value.Length != 4)
{
throw new InvalidVacKey("Invalid Input. Vaccination key must be exactly four characters.");
}
for (int i = 0; i < value.Length; i++)
{
// determines if it is an alphanumeric character
if (!Char.IsLetter(value[i]) && !Char.IsNumber(value[i]))
{
throw new InvalidVacKey("Invalid input. Vaccination key must be an alphanumeric character.");
}
}
vacKey = value;
}
}
public string VacDate
{
get { return vacDate; }
set
{
// split our value at the / and return an array of strings
String[] dateDate = value.Split('/');
if (dateDate.Length == 3)
{
int intYear;
int intMonth;
int intDay;
// check and see if the first element is numeric
if (!int.TryParse(dateDate[0], out intMonth))
{
throw new InvalidVacDate("Month value must be numeric.");
}
else
{
if (intMonth > 12 || intMonth < 1)
{
throw new InvalidVacDate("Month is out of range.");
}
}
// check and see if next element is numeric and within range
if (!int.TryParse(dateDate[1], out intDay))
{
throw new InvalidVacDate("Day value must be numeric");
}
else
{
if (intDay > 31 || intDay < 1)
{
throw new InvalidVacDate("Day is out of range.");
}
}
// check and see if last element is a year
if (!int.TryParse(dateDate[2], out intYear))
{
throw new InvalidVacDate("Year value must be numeric.");
}
else
{
if (intYear > 24 || intYear < 0)
{
throw new InvalidVacDate("Year value is out of range.");
}
}
}
else
{
throw new InvalidVacDate("Date must be in the format MM/DD/YY");
}
vacDate = value;
}
}
public string VacPerson
{
get { return vacPerson; }
set { vacPerson = value; }
}
// overloaded constructor that allows us to instantiate our class
public VaccinationRecords(string vacKey, string vacDate, string vacPerson)
{
this.VacKey = vacKey;
this.VacDate = vacDate;
this.VacPerson = vacPerson;
}
}
}