-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathUniversity.java
274 lines (177 loc) · 4.96 KB
/
University.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
/*
this program is used to find minimum distance between two vertices while traversing all available vertices.
*/
import java.util.*;
/**
* This class is to represent a Student
*
*/
class Students {
String name = "";
int roll = 0;
double cgpa = 0.0;
Students(String name, int roll, double cgpa) {
this.name = name;
this.roll = roll;
this.cgpa = cgpa;
}
Students() {
}
//Student setter method
void setstu(String name, int roll, double cgpa) {
this.name = name;
this.roll = roll;
this.cgpa = cgpa;
}
//Student getter method
void getstu() {
System.out.println(name + "\t" + roll + "\t" + cgpa);
}
}
/**
* This class is to represent a Semester with containing students and other
* information
*
*/
class Sem {
ArrayList<Students> li;
void setsem() {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of Students in this Sem :");
int n = in.nextInt();
li = new ArrayList<Students>(n);
String name;
int roll;
double cgpa;
Students obj;
for (int i = 0; i < n; ++i) {
obj = new Students();
System.out.println("Student " + (i + 1) + " :");
System.out.print("Enter name :");
name = in.next();
System.out.print("Enter roll :");
roll = in.nextInt();
System.out.print("Enter cgpa :");
cgpa = in.nextDouble();
obj.setstu(name, roll, cgpa);
li.add(obj);
}
}
void showsem() {
System.out.println("Name\tRoll\tCGPA");
for (Students i : li) {
i.getstu();
}
}
}
/**
* This class represnts a Course in a Institute
*
*/
class Course {
String name;
ArrayList<Sem> li;
void setcourse() {
Scanner in = new Scanner(System.in);
System.out.println("Enter name of this Course :");
name = in.next();
System.out.print("Enter number of Sem in this Course :");
int n = in.nextInt();
li = new ArrayList<Sem>(n);
Sem obj;
for (int i = 0; i < n; i++) {
obj = new Sem();
System.out.println("\tSemester " + (i + 1) + " :");
obj.setsem();
li.add(obj);
}
}
void showcourse() {
int c = 1;
System.out.println(name);
for (Sem i : li) {
System.out.println("\tSemester " + c);
i.showsem();
c++;
}
}
}
/**
* This class represents a Department in a Institute
*
*/
class Department {
String name;
ArrayList<Course> li;
void setdept() {
Scanner in = new Scanner(System.in);
System.out.println("Enter name of this Department :");
name = in.nextLine();
System.out.print("Enter number of Courses in this Department :");
int n = in.nextInt();
li = new ArrayList<Course>(n);
Course obj;
for (int i = 0; i < n; i++) {
obj = new Course();
System.out.println("\tCourse " + (i + 1) + " :");
obj.setcourse();
li.add(obj);
}
}
/*this funtion is used show the all item */
void showdept()
{
int c=1;
System.out.println(name);
for (Course i : li) {
System.out.print("\tCourse " + c + " :");
i.showcourse();
c++;
}
}
}
/**
* This class represents an Institute
*
*/
class Institute {
String name;
ArrayList<Department> li;
void setinst() {
Scanner in = new Scanner(System.in);
System.out.println("Enter name of this Institute :");
name = in.next();
System.out.print("Enter number of Departments in this Institute :");
int n = in.nextInt();
li = new ArrayList<Department>(n);
Department obj;
for (int i = 0; i < n; i++) {
obj = new Department();
System.out.println("\tDepartment " + (i + 1) + " :");
obj.setdept();
li.add(obj);
}
}
void showinst() {
int c = 1;
System.out.println(name);
for (Department i : li) {
System.out.print("\tDepartment " + c + " :");
i.showdept();
c++;
}
}
}
/**
* This class represents a University containing one or more Institute
*
*/
public class University {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Welcome!");
Institute obj = new Institute();
obj.setinst();
obj.showinst();
}
}