Skip to content

Commit 2f8dc67

Browse files
committedJan 15, 2025
Second Program
1 parent 136dc66 commit 2f8dc67

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
 

‎TeacherStudent.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
public class TeacherStudent {
2+
3+
// Teacher class
4+
public static class Teacher {
5+
private String tname;
6+
private String subject;
7+
private int yrsOfExp;
8+
9+
public Teacher(String tname, String subject, int yrsOfExp) {
10+
this.tname = tname;
11+
this.subject = subject;
12+
this.yrsOfExp = yrsOfExp;
13+
}
14+
15+
public String getTname() {
16+
return tname;
17+
}
18+
19+
public void setTname(String tname) {
20+
this.tname = tname;
21+
}
22+
23+
public String getSubject() {
24+
return subject;
25+
}
26+
27+
public void setSubject(String subject) {
28+
this.subject = subject;
29+
}
30+
31+
public int getYrsOfExp() {
32+
return yrsOfExp;
33+
}
34+
35+
public void setYrsOfExp(int yrsOfExp) {
36+
this.yrsOfExp = yrsOfExp;
37+
}
38+
}
39+
40+
// Student class
41+
public static class Student {
42+
private String sname;
43+
private String degree;
44+
private String college;
45+
46+
public Student(String sname, String degree, String college) {
47+
this.sname = sname;
48+
this.degree = degree;
49+
this.college = college;
50+
}
51+
52+
public String getSname() {
53+
return sname;
54+
}
55+
56+
public void setSname(String sname) {
57+
this.sname = sname;
58+
}
59+
60+
public String getDegree() {
61+
return degree;
62+
}
63+
64+
public void setDegree(String degree) {
65+
this.degree = degree;
66+
}
67+
68+
public String getCollege() {
69+
return college;
70+
}
71+
72+
public void setCollege(String college) {
73+
this.college = college;
74+
}
75+
}
76+
77+
// Static method to show relationship between teacher and student
78+
public static void showRelationship(Teacher teacher, Student student) {
79+
System.out.println(student.getSname() + " takes " + teacher.getSubject() + " class under " + teacher.getTname() + " Sir");
80+
}
81+
82+
// Static method to show a detailed relationship
83+
public static void showCompleteRelationship(Teacher teacher, Student student) {
84+
System.out.println(teacher.getTname() + " sir teaches " + teacher.getSubject() + " to " + student.getSname() +
85+
" who reads as a " + student.getDegree() + " student in " + student.getCollege() + " college");
86+
}
87+
88+
// Main method
89+
public static void main(String[] args) {
90+
Teacher teacher1 = new Teacher("Amitava", "OOPS design", 10);
91+
Teacher teacher2 = new Teacher("Amitava", "Java", 5);
92+
93+
Student student1 = new Student("Ankan", "Btech", "UEM");
94+
Student student2 = new Student("Madhu", "Btech", "UEM");
95+
96+
// Show relationships
97+
showRelationship(teacher2, student1); // Ankan takes Java class under Amitava Sir
98+
showCompleteRelationship(teacher1, student2); // Amitava teaches OOPS design to Madhu
99+
}
100+
}

0 commit comments

Comments
 (0)
Please sign in to comment.