-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
90 lines (77 loc) · 2.6 KB
/
Program.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
using System;
using PayrollApp.Data;
namespace PayrollApp;
/// <summary>
/// Program class only consists of Main() method where all the calls are made.
/// </summary>
class Program
{
private static void Main(string[] args)
{
List<Staff> myStaff = new List<Staff>();
FileReader fr = new FileReader();
int month = 0, year = 0;
// Input the year
while (year == 0)
{
Console.WriteLine("\nPlease enter the year: ");
try
{
// Code to convert the input to an integer
year = Convert.ToInt32(Console.ReadLine());
}
catch (Exception e)
{
// Code to handle the exception
Console.WriteLine("You have entered non-numeric characters. Try again");
}
}
// Input the month
while (month == 0)
{
Console.WriteLine("\nPlease enter the month: ");
try
{
// Code to convert the input to an integer
month = Convert.ToInt32(Console.ReadLine());
// Check the data range of the input
if (month < 1 || month > 12)
{
Console.WriteLine("Invalid month range. Enter a valid number");
month = 0;
}
}
catch (Exception e)
{
// Code to handle the exception
Console.WriteLine("You have entered non-numeric characters. Try again");
}
}
// Read the file and insert the contents to myStaff list
myStaff = fr.ReadFile();
// Loop through myStaff list to set the hours
for (int i = 0; i < myStaff.Count; i++)
{
try
{
// Enter the hours for each staff and calculate its pay + print summary
Console.WriteLine("Enter hours worked for {0}", myStaff[i].NameOfStaff);
myStaff[i].HoursWorked = Convert.ToInt32(Console.ReadLine());
myStaff[i].CalculatePay();
Console.WriteLine(myStaff[i].ToString());
}
catch (Exception e)
{
// Code to handle the exception
Console.WriteLine("You have entered non-numeric characters. Try again");
i--;
}
}
// Generate payslips for each member in myStaff list
PaySlip ps = new PaySlip(month, year);
ps.GeneratePaySlip(myStaff);
ps.GenerateSummary(myStaff);
Console.ReadLine();
}
}