Sajib_Ahmed

Untitled

Apr 2nd, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.29 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.print("Name:"+name+"\nAge:"+age+"\n");
  20.        
  21.     }
  22.    
  23.    
  24. }
  25.  
  26. package class_work;
  27.  
  28.  
  29. public class Teacher extends Person{
  30.      private String designation,dept;
  31.    
  32.  
  33.     public Teacher(String name1,int age1,String designation, String dept) {
  34.         super(name1,age1);
  35.         this.designation = designation;
  36.         this.dept = dept;
  37.     }
  38.  
  39.     public String getDesignation() {
  40.         return designation;
  41.     }
  42.  
  43.     public String getDept() {
  44.         return dept;
  45.     }
  46.    
  47.     public void display()
  48.     {
  49.         super.display();
  50.         System.out.println("Designation:"+designation+"\nDepartment"+dept+"\n");
  51.     }
  52.    
  53. }
  54.  
  55. package class_work;
  56.  
  57.  
  58. public class Student extends Person {
  59.      private String id;
  60.      private double cgpa;
  61.  
  62.     public Student(String name,int age,String id, double cgpa) {
  63.         super(name,age);
  64.         this.id = id;
  65.         this.cgpa = cgpa;
  66.        
  67.     }
  68.  
  69.     public String getId() {
  70.         return id;
  71.     }
  72.  
  73.     public double getCgpa() {
  74.         return cgpa;
  75.     }
  76.    
  77.    
  78.     public void display()
  79.     {
  80.          super.display();
  81.          System.out.println("ID:"+id+"\nCGPA:"+cgpa+"\n");
  82.     }
  83.    
  84. }
  85.  
  86. package class_work;
  87.  
  88. import java.util.Scanner;
  89. public class Department {
  90.     private String depName;
  91.     private int depCode;
  92.     Student student;
  93.     Teacher teacher;
  94.  
  95.     public Department(String depName, int depCode,Student student,Teacher teacher) {
  96.         this.depName = depName;
  97.         this.depCode = depCode;
  98.         this.student=student;
  99.         this.teacher=teacher;
  100.     }
  101.    
  102.     public void displayAll()
  103.     {
  104.         System.out.println("Student portal :\nName:"+student.name+"\nAge:"+student.age+"\nID:"+student.getId()+"\nCGPA:"+student.getCgpa()+"\nDepartment:"+depName+"\nDepartment Code:"+depCode+"\n");
  105.         System.out.println("Teacher portal :\nName:"+teacher.name+"\nAge:"+teacher.age+"\nDESIGNATION:"+teacher.getDesignation()+"\nTeacher Department:"+teacher.getDept()+"\nDepartment"+depName+"\nDepartment Code:"+depCode+"\n");
  106.        
  107.     }
  108.     public static void main(String[] args)
  109.            
  110.     {
  111.        
  112.         Scanner Input=new Scanner(System.in);
  113.         System.out.println("Enter number of student and teacher");
  114.         int n=Input.nextInt();
  115.         Department []obj=new Department[n];
  116.           Student []obj1=new Student[n];
  117.           Teacher []obj2=new Teacher[n];
  118.             for(int i=0;i<n;i++){
  119.                 Input.nextLine();
  120.              System.out.print("Student name=");
  121.              String name=Input.nextLine();
  122.               System.out.print("Student Age=");
  123.               int age=Input.nextInt();
  124.               Input.nextLine();
  125.               System.out.print("Student Id=");
  126.               String id=Input.nextLine();
  127.               System.out.print("Student CGPA=");
  128.               double cgpa= Input.nextDouble();
  129.               Input.nextLine();
  130.               System.out.print("Teacher name=");
  131.               String name1=Input.nextLine();
  132.               System.out.print("Teacher Age=");
  133.               int age1=Input.nextInt();
  134.               Input.nextLine();
  135.               System.out.print("Teacher designation=");
  136.               String designation=Input.nextLine();
  137.               System.out.print("Teacher dept=");
  138.               String dept=Input.nextLine();
  139.               System.out.print("deptName=");
  140.               String deptName = Input.next();
  141.               System.out.print("deptCode=");
  142.               int deptCode = Input.nextInt();
  143.               obj1[i]=new Student(name,age,id,cgpa);
  144.               System.out.println("Student Information\n");
  145.             obj1[i].display();
  146.              obj2[i]=new Teacher(name1,age1,designation,dept);
  147.              System.out.println("Teacher Information\n");
  148.             obj2[i].display();
  149.             obj[i] = new  Department(deptName,deptCode,obj1[i],obj2[i]);
  150.             System.out.println("All Informatin\n");
  151.             obj[i].displayAll();
  152.          
  153.        
  154.     }
  155.        
  156.        
  157.        
  158.        
  159.        
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment