Advertisement
Sajib_Ahmed

Untitled

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