-
Notifications
You must be signed in to change notification settings - Fork 0
/
Course.java~
336 lines (273 loc) · 8.56 KB
/
Course.java~
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import java.io.*;
import java.util.*;
public class Course implements java.io.Serializable
{
// data-members
private String course_name;
private double fees;
private String start;
private Integer duration_days;
private Integer num_of_fac;
private Integer num_of_part;
Faculty course_coord;
Vector <Faculty> course_fac = new Vector <Faculty> ();
Vector <Participant> reg_part = new Vector <Participant> ();
/**********************************/
//constructors
Course () {
course_name = " ";
fees = 0.0;
start = " ";
duration_days = 0;
num_of_fac= 0;
num_of_part= 0;
course_coord= new Faculty();
}
//setters
void set_course_name ( String s ) {
course_name = s;
}
void set_course_fee ( double f ) {
fees = f;
}
void set_start_date ( String s ) {
start = s;
}
void set_course_duration ( int dd ) {
duration_days = dd;
}
void set_num_of_fac (int n) {
num_of_fac = n;
}
void set_num_of_part (int n) {
num_of_part = n;
}
//getters
String get_course_name () {
return course_name;
}
double get_course_fee () {
return fees;
}
String get_start_date(){
return start;
}
int get_course_duration () {
return duration_days;
}
int get_num_of_fac () {
return num_of_fac;
}
int get_num_of_part () {
return num_of_part;
}
// methods
boolean valid_course () {
if( duration_days > 14 ) {
System.out.println("Invalid course duration. Maximum 14 days allowed. \n");
return false;
}
return true;
}
void delete_part(int i){
reg_part.remove(i);
}
void delete_fac(int i){
course_fac.remove(i);
}
void display_course() {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("-- Course Details --");
System.out.println("Course Name: "+ course_name);
System.out.println("Course Start Date: "+ start);
System.out.println("Course Fees: INR "+ fees);
System.out.println("Course Duration: "+ duration_days + " days");
System.out.println("Course Coordinator: "+ course_coord.get_fac_name() );
if(num_of_fac > 0){
System.out.println("Associsted Faculty List:");
for(int i=0;i<num_of_fac;i++)
System.out.println("Faculty #"+(i+1)+" : "+course_fac.elementAt(i).get_fac_name() );
}
else
System.out.println("No associated faculty.");
num_of_part = reg_part.size();
if(num_of_part > 0){
System.out.println("Registered Participant List: ");
for(int i=0;i<num_of_part;i++)
System.out.println("Participant #"+(i+1)+" : "+reg_part.elementAt(i).get_part_name() );
}
else
System.out.println("No registered participant yet.");
System.out.println("\n--------****---------\n");
}
void display_course_name() {
System.out.println("Course Name: "+ course_name);
}
void create_course() throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("\n-- Course Creation Portal-- ");
//try{
System.out.println("Enter the details as mentioned.");
System.out.print("\n-- i. Course-name : ");
String cn = br.readLine();
course_name= cn;
System.out.print("\n-- ii. Course fee (in INR) : ");
double fe = 0;
try{
fe= Double.parseDouble(br.readLine());
}
catch(Exception e){
System.out.println("Please enter valid integer");
}
fees= fe;
System.out.print("\n-- iii. Course start-date (dd/mm/yyyy in a single string) : ");
String st = br.readLine();
start = st;
System.out.print("\n-- iv. Course duration (in days): ");
int du = 0;
try{
du= Integer.parseInt(br.readLine());
}
catch(Exception e){
System.out.println("Please enter valid integer");
}
duration_days= du;
System.out.println("------------------------------------------------");
System.out.println("\nDetails Noted. Redirecting to course co-ordinator creation directive...\n");
for(int i=0; i < 100000000; i++) ;
course_coord.create_faculty();
System.out.println("\nDetails Noted. Enter the number of faculty associated with the course.");
int n = 0;
try{
n= Integer.parseInt(br.readLine());
while(n < 0 || n > 5){
System.out.println("Enter a non-negative value less than 5. ");
n= Integer.parseInt(br.readLine());
}
}
catch(Exception e){
System.out.println("Please enter valid integer");
}
num_of_fac= n;
for(int i=0; i<num_of_fac; i++){
System.out.println("\n------------------------------");
System.out.println("\n\nFaculty Number : "+(i+1));
Faculty c = new Faculty();
course_fac.addElement(c);
course_fac.elementAt(i).create_faculty();
}
num_of_fac = course_fac.size();
num_of_part = reg_part.size();
//}
//catch(Exception et){
//System.out.println("Invalid input");
//}
}
void register_part(int i)throws IOException{
num_of_part = reg_part.size();
if(num_of_part == 5){
System.out.println("There can be a maximum of 5 participants");
return;
}
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Participant c = new Participant();
reg_part.addElement(c);
num_of_part = reg_part.size();
reg_part.elementAt(i).create_participant();
System.out.println("\n-- Participant details noted successfully --\n");
}
void display_participants(){
num_of_part = reg_part.size();
for(int i=0;i<num_of_part;i++)
System.out.println("Participant #"+(i+1)+" is : "+ reg_part.elementAt(i).get_part_name());
}
//search for faculty
boolean search_fac_by_name (String n) {
boolean vv = false;
if((course_coord.get_fac_name()).equals(n) == true)
vv = true;
else{
for(int i=0; i< num_of_fac; i++){
if((course_fac.elementAt(i).get_fac_name()).equals(n) == true)
vv = true;
}
}
return vv;
}
//search for participant
boolean search_part_by_name (String n) {
boolean vv = false;
for(int i=0; i< num_of_part; i++){
if((reg_part.elementAt(i).get_part_name()).equals(n) == true)
vv = true;
}
return vv;
}
void edit_course()throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Which field do you want to edit");
System.out.println("1 - Course Name");
System.out.println("2 - Start- date");
System.out.println("3 - Fees");
System.out.println("4 - Duration of course");
System.out.println("5 - Course Coordinator");
int cco = 0;
String stt;
int stri;
try{
cco = Integer.parseInt(br.readLine());
}
catch(Exception e){
System.out.println("Enter valid credentials");
}
switch(cco)
{
//try{
case 1: System.out.println("Enter the changed course name");
stt= br.readLine();
set_course_name(stt);
System.out.println("Course Name changed to : "+ get_course_name());
break;
case 2: System.out.println("Enter the changed start date");
stt= br.readLine();
set_start_date(stt);
System.out.println("Course Start Date changed to : "+ get_start_date());
break;
case 3: System.out.println("Enter the changed course fee");
double fees_c = 0.0;
try{
fees_c = Double.parseDouble(br.readLine());
}
catch(Exception e){
System.out.println("Enter a valid floating type value");
}
set_course_fee(fees_c);
System.out.println("Course Fees changed to : "+ get_course_fee());
break;
case 4: System.out.println("Enter the changed course duration");
stri = 0;
try{
stri = Integer.parseInt(br.readLine());
while(stri < 0){
System.out.println("Duration can't be negative. Try again.");
stri = Integer.parseInt(br.readLine());
}
}
catch(Exception e){
System.out.println("Enter a valid integer as course duration in days.");
}
set_course_duration(stri);
System.out.println("Course Fees changed to : "+ get_course_duration());
break;
case 5: System.out.println("Enter the details of the changed course coordinator");
course_coord.create_faculty();
System.out.println("Course Coordinator changed to " + course_coord.get_fac_name());
break;
// }
// catch(Exception e){
// System.out.println("Enter the details in valid format");
// }
default : System.out.println("Invalid entry");
}
}
}