-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
241 lines (153 loc) · 6.7 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
namespace Student_Register_System
{
internal class Program
{
class Students
{
private string m_fName;
private string m_sName;
private int m_age;
//To autogenerate a property do the following: type "prop" then press TAB TAB
public string fName { get { return m_fName; } set { m_fName = value; } }
public string sName { get { return m_sName; } set { m_sName = value; } }
public int Age { get { return m_age; } set { m_age = value; } }
public Students(string fName, string sName, int age)
{
m_fName = fName;
m_sName = sName;
m_age = age;
}
public string GetFullName()
{
return m_fName + " " + m_sName;
}
}
static int RunMenu(string[] menuItems)
{
Console.WriteLine(menuItems[0] + "\n");
for (int i = 1; i < menuItems.Length; i++)
{
Console.WriteLine(i + ": " + menuItems[i]);
}
int menuChoice = 0;
try
{
Console.WriteLine("\nPlease enter your selection from the list provided:");
menuChoice = Convert.ToInt16(Console.ReadLine());
Console.Clear();
if (menuChoice < 1 || menuChoice >= menuItems.Length)
{
throw new Exception(); //Make sure to improve the error handling section for this area!!!!
}
}
catch
{
Console.WriteLine("Sorry, an unexpected error has occured. Please try again...\n[Press Enter to Try Again]");
Console.ReadLine();
Console.Clear();
}
return menuChoice;
}
static void DisplayStudents(List<Students> students)
{
if (students.Count == 0)
{
Console.WriteLine("There are currently no unassigned Students...\n");
}
else
{
Console.WriteLine("-----------Students-----------");
for (int i = 0; i < students.Count; i++)
{
Console.WriteLine("Name: " + students[i].GetFullName());
Console.WriteLine("Age: " + students[i].Age + "\n");
}
}
}
static List<Students> RegStudents(List<Students> unassignedStudents)
{
int menuChoice = 0;
do
{
DisplayStudents(unassignedStudents);
string[] menuItems = { "-----------Register-----------", "Add New Student", "Return to Menu" };
menuChoice = RunMenu(menuItems);
if (menuChoice == 1)
{
string fName = "";
string sName = "";
int age = 0;
do
{
Console.WriteLine("Please enter the students first name:");
fName = Console.ReadLine();
Console.Clear();
Console.WriteLine("Please enter the students second name:");
sName = Console.ReadLine();
Console.Clear();
bool isValid = true;
do
{
try
{
Console.WriteLine("Please enter the students age:");
age = Convert.ToInt16(Console.ReadLine());
Console.Clear();
isValid = true; //Improve this validation section as well!!!!!
}
catch
{
Console.WriteLine("Error, Please try that again\n[Press Enter to Try Again]");
Console.ReadLine();
Console.Clear();
isValid = false;
}
} while (isValid == false);
Console.WriteLine("---------New Student Details---------\n\nFirst Name: " + fName + "\nSecond Name: " + sName + "\nAge: " + age + "\n");
string[] newMenuItems = { "Is this information correct?", "Yes", "No" };
menuChoice = RunMenu(newMenuItems);
} while (menuChoice != 1);
unassignedStudents.Add(new Students(fName, sName, age));
Console.WriteLine("You have successfully added " + unassignedStudents[unassignedStudents.Count - 1].GetFullName() + "!\n[Press Enter to Continue]");
Console.ReadLine();
Console.Clear();
}
} while (menuChoice != 2);
return unassignedStudents;
}
static void Main(string[] args)
{
int menuChoice = 0;
do
{
string[] menuItems = { "-----------Menu-----------", "Register Student", "Assign Student to Class", "Take Register", "Close" };
menuChoice = RunMenu(menuItems);
List<Students> unassignedStudents = new List<Students>();
//-------------------This code is for development purposes only, remove when complete-----------
unassignedStudents.Add(new Students("Jay", "Miles", 29));
unassignedStudents.Add(new Students("Ben", "Hobbs", 28));
unassignedStudents.Add(new Students("Jon", "Barnett", 30));
unassignedStudents.Add(new Students("Will", "Price", 38));
unassignedStudents.Add(new Students("Jack", "Burnett", 24));
//----------------------------------------------------------------------------------------------
switch (menuChoice)
{
case 1:
RegStudents(unassignedStudents);
break;
case 2:
Console.WriteLine("Assign Student to Class coming soon...");
break;
case 3:
Console.WriteLine("Take Register coming soon...");
break;
case 4:
Console.WriteLine("Good Bye\n[Press Enter to Close]");
Console.ReadLine();
break;
}
} while (menuChoice != 4);
}
}
}