-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeacherStudent.java
100 lines (79 loc) · 2.85 KB
/
TeacherStudent.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
public class TeacherStudent {
// Teacher class
public static class Teacher {
private String tname;
private String subject;
private int yrsOfExp;
public Teacher(String tname, String subject, int yrsOfExp) {
this.tname = tname;
this.subject = subject;
this.yrsOfExp = yrsOfExp;
}
public String getTname() {
return tname;
}
public void setTname(String tname) {
this.tname = tname;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public int getYrsOfExp() {
return yrsOfExp;
}
public void setYrsOfExp(int yrsOfExp) {
this.yrsOfExp = yrsOfExp;
}
}
// Student class
public static class Student {
private String sname;
private String degree;
private String college;
public Student(String sname, String degree, String college) {
this.sname = sname;
this.degree = degree;
this.college = college;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getDegree() {
return degree;
}
public void setDegree(String degree) {
this.degree = degree;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
}
// Static method to show relationship between teacher and student
public static void showRelationship(Teacher teacher, Student student) {
System.out.println(student.getSname() + " takes " + teacher.getSubject() + " class under " + teacher.getTname() + " Sir");
}
// Static method to show a detailed relationship
public static void showCompleteRelationship(Teacher teacher, Student student) {
System.out.println(teacher.getTname() + " sir teaches " + teacher.getSubject() + " to " + student.getSname() +
" who reads as a " + student.getDegree() + " student in " + student.getCollege() + " college");
}
// Main method
public static void main(String[] args) {
Teacher teacher1 = new Teacher("Amitava", "OOPS design", 10);
Teacher teacher2 = new Teacher("Amitava", "Java", 5);
Student student1 = new Student("Ankan", "Btech", "UEM");
Student student2 = new Student("Madhu", "Btech", "UEM");
// Show relationships
showRelationship(teacher2, student1); // Ankan takes Java class under Amitava Sir
showCompleteRelationship(teacher1, student2); // Amitava teaches OOPS design to Madhu
}
}