-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionalClasses.cs
More file actions
111 lines (103 loc) · 4.08 KB
/
FunctionalClasses.cs
File metadata and controls
111 lines (103 loc) · 4.08 KB
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
using System;
using System.IO;
namespace Assignment1
{
public class Sorter
{
public static Worker[] Sort(Worker[] input)
{
for (int i = 0; i < (input.Length) - 1; i++)
{
for (int j = 0; j < (input.Length) - 1; j++)
{
if (String.Compare(input[i].lastName, input[i+1].lastName) > 0)
{
Worker temp = input[i + 1];
input[i + 1] = input[i];
input[i] = temp;
}
}
}
return input;
}
}
public class FileReader
{
public static string[] read(string filePath) //Class for reading file input into string array
{
return File.ReadAllLines(filePath);
}
public static Worker[] objectify(string[] input) //Class for turning string array into object array
{
Worker[] workers = new Worker[input.Length-1];
for(int i=1; i<input.Length; i++)
{
string[] line = input[i].Split('\t',StringSplitOptions.RemoveEmptyEntries);
switch (line[0]) //store different data based on type of employee
{
case ("PreHire"):
PreHire p = new PreHire();
p.workerType = line[0]; //fill all data in new object
p.employeeID = int.Parse(line[1]);
p.firstName = line[2];
p.lastName = line[3];
p.offerDate = line[4];
p.acceptDate = line[5];
p.employmentDate = line[6];
workers[i-1] = p; //add to workers array for return
break;
case ("Employee"):
Employee e = new Employee();
e.workerType = line[0];
e.employeeID = int.Parse(line[1]);
e.firstName = line[2];
e.lastName = line[3];
e.employmentDate = line[4];
e.jobTitle = line[5];
e.monthlySalary = double.Parse(line[6]);
workers[i-1] = e;
break;
case ("Retiree"):
Retiree r = new Retiree();
r.workerType = line[0];
r.employeeID = int.Parse(line[1]);
r.firstName = line[2];
r.lastName = line[3];
r.employmentDate = line[4];
r.retirementProgram = line[5];
r.retirementDate = line[6];
workers[i-1] = r;
break;
}
}
return workers; //output array of workers read from file
}
}
public class FileWriter
{
public static void write(Worker[] workers, string pFile, string eFile, string rFile)
{
File.WriteAllText(pFile, "<PreHires>"); //write opening XML tags
File.WriteAllText(eFile, "<Employees>");
File.WriteAllText(rFile, "<Retirees>");
foreach (Worker w in workers) //iterate through workers, writing each into respective files in XML format
{
switch (w.workerType)
{
case ("PreHire"):
File.AppendAllText(pFile, w.toXML());
break;
case ("Employee"):
File.AppendAllText(eFile, w.toXML());
break;
case ("Retiree"):
File.AppendAllText(rFile, w.toXML());
break;
}
}
File.AppendAllText(pFile, "\n</PreHires>"); //write closing XML tags
File.AppendAllText(eFile, "\n</Employees>");
File.AppendAllText(rFile, "\n</Retirees>");
}
}
}