-
Notifications
You must be signed in to change notification settings - Fork 0
/
School registration.dart
204 lines (183 loc) · 4.44 KB
/
School registration.dart
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
Here's the Dart code for the school and subject selection process:
import 'dart:math';
void main() {
print('Welcome to the School Registration System!');
chooseSchool();
}
void chooseSchool() {
print('Select a school:');
print('1. School of Arts');
print('2. School of Science');
int choice = int.parse(readLine());
if (choice == 1 || choice == 2) {
chooseClass(choice);
} else {
print('Error: Invalid school choice.');
chooseSchool();
}
}
void chooseClass(int school) {
print('Select your class:');
print('1. Form 1');
print('2. Form 2');
print('3. Form 3');
print('4. Form 4');
print('5. Form 5');
print('6. Lower Sixth Arts');
print('7. Lower Sixth Science');
print('8. Upper Sixth Arts');
print('9. Upper Sixth Science');
int choice = int.parse(readLine());
if (choice >= 1 && choice <= 9) {
chooseSubjects(school, choice);
} else {
print('Error: Invalid class choice.');
chooseClass(school);
}
}
void chooseSubjects(int school, int class) {
List<String> subjects = getSubjects(class);
int minSubjects = getMinSubjects(class);
int maxSubjects = getMaxSubjects(class);
print('Select your subjects (choose minimum $minSubjects, maximum $maxSubjects):');
for (int i = 0; i < subjects.length; i++) {
print('${i + 1}. ${subjects[i]}');
}
List<int> choices = [];
int count = 0;
while (count < minSubjects) {
int choice = int.parse(readLine());
if (choices.contains(choice)) {
print('Error: Subject already chosen.');
} else if (choice > 0 && choice <= subjects.length) {
choices.add(choice);
count++;
} else {
print('Error: Invalid subject choice.');
}
}
if (count < maxSubjects) {
print('Do you want to choose additional subjects (y/n)?');
String answer = readLine();
if (answer.toLowerCase() == 'y') {
chooseAdditionalSubjects(choices, subjects);
}
}
print('Registration successful!');
}
List<String> getSubjects(int class) {
switch (class) {
case 1:
case 2:
return [
'French',
'English',
'Maths',
'Religious Studies',
'Biology',
'Geography',
'Computer Science',
'History',
'Citizenship',
'Chemistry',
'Physics',
'Literature',
'Food/Nutrition'
];
case 3:
return [
'French',
'English',
'Maths',
'Religious Studies',
'Biology',
'Geography',
'Computer Science',
'History',
'Citizenship',
'Chemistry',
'Physics',
'Literature',
'Food/Nutrition',
'Economics'
];
case 4:
case 5:
return [
'Maths',
'English',
'French',
'Biology',
'Geography',
'Religious Studies',
'Economics',
'Computer Science',
'History',
'Citizenship',
'Chemistry',
'Physics',
'Human Biology',
'Add Maths',
'Logic',
'Literature',
'Food/Nutrition',
'Geology'
];
case 6:
case 8:
return [
'Literature',
'History',
'Geography',
'Economics',
'ICT',
'Philosophy',
'French',
'Religious Studies',
'Maths (Statistics)'
];
case 7:
case 9:
return [
'Biology',
'Chemistry',
'Physics',
'Maths',
'Further Maths',
'Computer Science
default:
return [];
}
}
int getMinSubjects(int class) {
if (class <= 3) return 12;
return 7;
}
int getMaxSubjects(int class) {
if (class <= 3) return 12;
return 11;
}
void chooseAdditionalSubjects(List<int> choices, List<String> subjects) {
int maxChoices = getMaxSubjects(choices.length) - choices.length;
print('Select additional subjects (choose maximum $maxChoices):');
for (int i = 0; i < subjects.length; i++) {
if (!choices.contains(i + 1)) {
print('${i + 1}. ${subjects[i]}');
}
}
while (maxChoices > 0) {
int choice = int.parse(readLine());
if (choices.contains(choice)) {
print('Error: Subject already chosen.');
} else if (choice > 0 && choice <= subjects.length && !choices.contains(choice)) {
choices.add(choice);
maxChoices--;
} else {
print('Error: Invalid subject choice.');
}
}
}
// Simulates reading user input (replace with actual input methods)
String readLine() {
return stdin.readLineSync()!;
}