-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathMain4.java
More file actions
81 lines (66 loc) · 2.2 KB
/
Main4.java
File metadata and controls
81 lines (66 loc) · 2.2 KB
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
import java.util.*;
class University{
String uname;
ArrayList<Students> studentList = new ArrayList<Students>();
ArrayList <Departments> deptlist = new ArrayList<Departments>();
University(String uname, String[] snames,String[] dnames){
this.uname=uname;
for (int i=0; i<snames.length; i++){
studentList.add(new Students(snames[i]));
deptlist.add(new Departments (dnames[i]));
}
}
class Students{
String snames;
Departments dept;
Students(String snames){
this.snames=snames;
}
public void display(){
System.out.println("Student name is : "+snames);
System.out.println("Department is : "+ dept);
}
} // end of students class
class Departments{
String dnames;
ArrayList <Students> deptstudents = new ArrayList<Students>();
Departments(String dnames){
this.dnames=dnames;
}
public void displayStudents() {
for (int i = 0; i < deptstudents.size(); i++) {
System.out.println(deptstudents.get(i).snames);
}
}
}
Departments getDepartments(String name){
for (int i=0; i<deptlist.size(); i++) {
if (deptlist.get(i).dnames.equals(name))
return deptlist.get(i);
}
return null;
}
Students getStudents(String s) {
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).snames.equals(s))
return studentList.get(i);
}
return null;
}
public void enrollIn(Departments d, Students s){
s.dept=d;
d.deptstudents.add(s);
}
public void displayStudentindept(Departments d){
d.displayStudents();
}
} // end of university class
public class Main4 {
public static void main(String[] args){
String[] snames={"ali","mohsin","ahsan","zakir","zobiya","yusra"};
String[] dept={"SW","CS","TL"};
University muet = new University("Mehran UET",snames,dept);
muet.enrollIn(muet.getDepartments("SW"), muet.getStudents("mohsin") );
muet.displayStudentindept(muet.getDepartments("SW"));
}
}