Sajib_Ahmed

class

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