Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. package class_work;
- 2.
- 3.
- 4. public class Person {
- 5.
- 6.
- 7. protected String name;
- 8. protected int age;
- 9.
- 10. public Person(String name,int age)
- 11. {
- 12. this.name=name;
- 13. this.age=age;
- 14.
- 15. }
- 16. public void display()
- 17. {
- 18. System.out.println(name+"\n"+age+"\n");
- 19.
- 20. }
- 21.
- 22.
- 23. }
- 24.
- 25. package class_work;
- 26.
- 27.
- 28. public class Student extends Person {
- 29. String id;
- 30. double cgpa;
- 31.
- 32. public Student(String name,int age,String id, double cgpa) {
- 33. super(name,age);
- 34. this.id = id;
- 35. this.cgpa = cgpa;
- 36.
- 37. }
- 38.
- 39. public void display()
- 40. {
- 41. super.display();
- 42. System.out.println(id+"\n"+cgpa+"\n");
- 43. }
- 44.
- 45. }
- 46.
- 47. package class_work;
- 48.
- 49.
- 50. public class Teacher extends Person{
- 51. String designation,dept;
- 52.
- 53.
- 54. public Teacher(String name1,int age1,String designation, String dept) {
- 55. super(name1,age1);
- 56. this.designation = designation;
- 57. this.dept = dept;
- 58. }
- 59. public void display()
- 60. {
- 61. super.display();
- 62. System.out.println(designation+"\n"+dept+"\n");
- 63. }
- 64.
- 65. }
- 66.
- 67. package class_work;
- 68.
- 69. import java.util.Scanner;
- 70. public class Department {
- 71. private String depName;
- 72. private int depCode;
- 73. Student student;
- 74. Teacher teacher;
- 75.
- 76. public Department(String depName, int depCode,Student student,Teacher teacher) {
- 77. this.depName = depName;
- 78. this.depCode = depCode;
- 79. this.student=student;
- 80. this.teacher=teacher;
- 81. }
- 82. public void displayAll()
- 83. {
- 84. System.out.println("Student portal :\n"+student.name+"\n"+student.age+""+student.id+"\n"+student.cgpa+"\n"+depName+"\n"+depCode+"\n");
- 85. System.out.println("Teacher portal :\n"+teacher.name+"\n"+teacher.age+""+teacher.designation+"\n"+teacher.dept+"\n"+depName+"\n"+depCode+""+teacher.name+"\n");
- 86.
- 87. }
- 88. public static void main(String[] args)
- 89.
- 90. {
- 91.
- 92. Scanner Input=new Scanner(System.in);
- 93. System.out.println("Enter number of student and teacher");
- 94. int n=Input.nextInt();
- 95. Department []obj=new Department[n];
- 96. Student []obj1=new Student[n];
- 97. Teacher []obj2=new Teacher[n];
- 98. for(int i=0;i<n;i++){
- 99. Input.nextLine();
- 100. System.out.print("Student name=");
- 101. String name=Input.nextLine();
- 102. System.out.print("Student Age=");
- 103. int age=Input.nextInt();
- 104. Input.nextLine();
- 105. System.out.print("Student Id=");
- 106. String id=Input.nextLine();
- 107. System.out.print("Student CGPA=");
- 108. double cgpa= Input.nextDouble();
- 109. Input.nextLine();
- 110. System.out.print("Teacher name=");
- 111. String name1=Input.nextLine();
- 112. System.out.print("Teacher Age=");
- 113. int age1=Input.nextInt();
- 114. Input.nextLine();
- 115. System.out.print("Teacher designation=");
- 116. String designation=Input.nextLine();
- 117. System.out.print("Teacher dept=");
- 118. String dept=Input.nextLine();
- 119. System.out.print("deptName=");
- 120. String deptName = Input.next();
- 121. System.out.print("deptCode=");
- 122. int deptCode = Input.nextInt();
- 123. obj1[i]=new Student(name,age,id,cgpa);
- 124. System.out.println("Student Information\n");
- 125. obj1[i].display();
- 126. obj2[i]=new Teacher(name1,age1,designation,dept);
- 127. System.out.println("Teacher Information\n");
- 128. obj2[i].display();
- 129. obj[i] = new Department(deptName,deptCode,obj1[i],obj2[i]);
- 130. System.out.println("All Informatin\n");
- 131. obj[i].displayAll();
- 132.
- 133.
- 134. }
- 135.
- 136.
- 137.
- 138.
- 139.
- 140. }
- 141. }
Advertisement
Add Comment
Please, Sign In to add comment