FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Examples/Example1/Worksheet5/MainProgram.cs at master · TheGer/Examples · GitHub
TheGer
/
Examples
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
2
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Examples
/
Example1
/
Worksheet5
/
MainProgram.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
293 lines (215 loc) · 7.81 KB
Breadcrumbs
Examples
/
Example1
/
Worksheet5
/
MainProgram.cs
Copy path
File metadata and controls
293 lines (215 loc) · 7.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
using
System
.
Text
;
using
System
.
Threading
.
Tasks
;
using
System
.
Windows
.
Forms
;
namespace
Worksheet5
{
class
MainProgram
{
public
static
List
<
Classroom
>
rooms
;
public
static
Classroom
copyClassroom
(
Classroom
c1
)
{
Classroom
copy
=
new
Classroom
(
c1
.
Classroomname
,
c1
.
Projectoravailable
,
c1
.
Computersinclassroom
)
;
return
copy
;
}
//static method which will load a menu
static
void
Menu
(
String
menutext
)
{
int
option
=
0
;
while
(
option
!=
7
)
{
Console
.
WriteLine
(
menutext
)
;
option
=
Convert
.
ToInt32
(
Console
.
ReadKey
(
false
)
.
KeyChar
.
ToString
(
)
)
;
switch
(
option
)
{
case
1
:
opt1
(
)
;
break
;
case
2
:
opt2
(
)
;
break
;
case
3
:
opt3
(
)
;
break
;
case
4
:
opt4
(
)
;
break
;
case
5
:
opt5
(
)
;
break
;
case
6
:
opt6
(
)
;
break
;
case
7
:
opt7
(
)
;
break
;
case
8
:
break
;
default
:
Console
.
WriteLine
(
"Error - incorrect option"
)
;
break
;
}
}
}
static
void
opt7
(
)
{
ClassroomsForm
frm
=
new
ClassroomsForm
(
)
;
Application
.
Run
(
frm
)
;
}
static
void
opt1
(
)
{
//list all classrooms
foreach
(
Classroom
c
in
rooms
)
{
Console
.
WriteLine
(
c
)
;
}
}
static
void
opt2
(
)
{
int
roomscounter
=
0
;
foreach
(
Classroom
c
in
rooms
)
{
if
(
c
!=
null
)
{
roomscounter
++
;
}
}
Console
.
WriteLine
(
"Enter new classroom name: "
)
;
string
classroomname
=
Convert
.
ToString
(
Console
.
ReadLine
(
)
)
;
Console
.
WriteLine
(
"Does the classroom have a projector? "
)
;
bool
projector
=
yesno
(
)
;
//create a new classroom with an empty array of computers
Classroom
newClassroom
=
new
Classroom
(
classroomname
,
projector
,
new
List
<
Computer
>
(
)
)
;
rooms
.
Add
(
newClassroom
)
;
}
static
void
opt3
(
)
{
int
counter
=
0
;
//1. select classroom
foreach
(
Classroom
cl
in
rooms
)
{
if
(
cl
!=
null
)
{
Console
.
WriteLine
(
counter
+
") "
+
cl
.
Classroomname
+
" "
)
;
counter
++
;
}
}
Console
.
WriteLine
(
"Select a classroom:"
)
;
int
classroomchoice
=
Convert
.
ToInt32
(
Console
.
ReadLine
(
)
)
;
//2. add computer to classroom
Computer
c
=
newComputer
(
)
;
List
<
Computer
>
computersInClassroom
=
rooms
[
classroomchoice
]
.
Computersinclassroom
;
computersInClassroom
.
Add
(
c
)
;
}
static
void
opt4
(
)
{
Console
.
WriteLine
(
"Select a classroom:"
)
;
int
classroomchoice
=
Convert
.
ToInt32
(
Console
.
ReadLine
(
)
)
;
//2. add computer to classroom
Computer
c
=
newComputer
(
)
;
List
<
Computer
>
computersInClassroom
=
rooms
[
classroomchoice
]
.
Computersinclassroom
;
int
i
=
0
;
foreach
(
Computer
comp
in
computersInClassroom
)
{
Console
.
WriteLine
(
i
+
") "
+
comp
.
Computername
+
" "
)
;
}
}
static
void
opt5
(
)
{
}
static
void
opt6
(
)
{
//1. create an array containing all the computers in all the rooms
List
<
Computer
>
allComputers
=
new
List
<
Computer
>
(
)
;
foreach
(
Classroom
c
in
rooms
)
{
if
(
c
!=
null
)
{
foreach
(
Computer
cm
in
c
.
Computersinclassroom
)
{
allComputers
.
Add
(
cm
)
;
}
}
}
allComputers
.
Sort
(
)
;
foreach
(
Computer
c
in
allComputers
)
{
Console
.
WriteLine
(
c
)
;
}
Console
.
ReadLine
(
)
;
}
static
bool
yesno
(
)
{
Console
.
WriteLine
(
"y/n?"
)
;
string
input
=
Convert
.
ToString
(
Console
.
ReadKey
(
false
)
.
KeyChar
)
;
bool
accept
=
false
;
if
(
input
==
"y"
)
accept
=
true
;
else
if
(
input
==
"n"
)
accept
=
false
;
return
accept
;
}
static
Computer
newComputer
(
)
{
Console
.
WriteLine
(
"Enter computer name:"
)
;
string
computer
=
Console
.
ReadLine
(
)
;
Console
.
WriteLine
(
"Enter computer status:"
)
;
string
status
=
Console
.
ReadLine
(
)
;
Console
.
WriteLine
(
"Enter number of faults:"
)
;
int
numberOfFaults
=
Convert
.
ToInt32
(
Console
.
ReadLine
(
)
)
;
Computer
pc
=
new
Computer
(
computer
,
status
,
numberOfFaults
)
;
return
pc
;
}
static
void
updateStatusAndFaults
(
Computer
pctoupdate
)
{
Console
.
WriteLine
(
"Enter computer status:"
)
;
string
status
=
Console
.
ReadLine
(
)
;
Console
.
WriteLine
(
"Enter number of faults:"
)
;
int
numberOfFaults
=
Convert
.
ToInt32
(
Console
.
ReadLine
(
)
)
;
pctoupdate
.
Computerstatus
=
status
;
pctoupdate
.
Numberoffaults
=
numberOfFaults
;
}
static
void
Main
(
string
[
]
args
)
{
//starting point of the application
//we will load the menu of the application
//here
rooms
=
new
List
<
Classroom
>
(
)
;
Computer
PC1
=
new
Computer
(
"L113-"
,
"OK"
,
5
)
;
Computer
PC2
=
new
Computer
(
"L11"
,
"OK"
,
2
)
;
Computer
PC3
=
new
Computer
(
"L1"
,
"NOT OK"
,
3
)
;
Computer
PC4
=
new
Computer
(
"L113-8"
,
"NOT OK"
,
3
)
;
Laptop
PC5
=
new
Laptop
(
"L113-9"
,
"NOT OK"
,
3
)
;
List
<
Computer
>
computers
=
new
List
<
Computer
>
(
)
;
computers
.
Add
(
PC1
)
;
computers
.
Add
(
PC2
)
;
computers
.
Add
(
PC3
)
;
computers
.
Add
(
PC4
)
;
computers
.
Add
(
PC5
)
;
//myClassroom = L113
Classroom
myClassroom
=
new
Classroom
(
"L113"
,
true
,
computers
)
;
List
<
Computer
>
computers2
=
new
List
<
Computer
>
(
)
;
computers2
.
Add
(
new
Computer
(
"L114-1"
,
"OK"
,
1
)
)
;
computers2
.
Add
(
new
Computer
(
"L114-2"
,
"OK"
,
5
)
)
;
//myClassroom2 = L114
Classroom
myClassroom2
=
new
Classroom
(
"L114"
,
true
,
computers2
)
;
//max classrooms = 4
//first 2 classrooms
rooms
.
Add
(
myClassroom
)
;
rooms
.
Add
(
myClassroom2
)
;
String
menu
=
"1.) List all classrooms in system
\t
\n
"
+
"2.) Add new classroom
\t
\n
"
+
"3.) Add new computer to classroom
\t
\n
"
+
"4.) List all computers in classroom
\t
\n
"
+
"5.) Update computer status by computer name
\t
\n
"
+
"6.) List all computers ordered by fault
\t
\n
"
+
"7.) GUI
\t
\n
"
+
"8.) Quit
\t
\n
"
;
Menu
(
menu
)
;
Console
.
ReadLine
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL