Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package class_work;
- public class Person {
- protected String name;
- protected int age;
- public Person(String name,int age)
- {
- this.name=name;
- this.age=age;
- }
- public void display()
- {
- System.out.println(name+"\n"+age+"\n");
- }
- }
- package class_work;
- public class Student extends Person {
- String id;
- double cgpa;
- public Student(String name,int age,String id, double cgpa) {
- super(name,age);
- this.id = id;
- this.cgpa = cgpa;
- }
- public void display()
- {
- super.display();
- System.out.println(id+"\n"+cgpa+"\n");
- }
- }
- package class_work;
- public class Teacher extends Person{
- String designation,dept;
- public Teacher(String name1,int age1,String designation, String dept) {
- super(name1,age1);
- this.designation = designation;
- this.dept = dept;
- }
- public void display()
- {
- super.display();
- System.out.println(designation+"\n"+dept+"\n");
- }
- }
- package class_work;
- import java.util.Scanner;
- public class Department {
- private String depName;
- private int depCode;
- Student student;
- Teacher teacher;
- public Department(String depName, int depCode,Student student,Teacher teacher) {
- this.depName = depName;
- this.depCode = depCode;
- this.student=student;
- this.teacher=teacher;
- }
- public void displayAll()
- {
- System.out.println("Student portal :\n"+student.name+"\n"+student.age+""+student.id+"\n"+student.cgpa+"\n"+depName+"\n"+depCode+"\n");
- System.out.println("Teacher portal :\n"+teacher.name+"\n"+teacher.age+""+teacher.designation+"\n"+teacher.dept+"\n"+depName+"\n"+depCode+""+teacher.name+"\n");
- }
- public static void main(String[] args)
- {
- Scanner Input=new Scanner(System.in);
- System.out.println("Enter number of student and teacher");
- int n=Input.nextInt();
- Department []obj=new Department[n];
- Student []obj1=new Student[n];
- Teacher []obj2=new Teacher[n];
- for(int i=0;i<n;i++){
- Input.nextLine();
- System.out.print("Student name=");
- String name=Input.nextLine();
- System.out.print("Student Age=");
- int age=Input.nextInt();
- Input.nextLine();
- System.out.print("Student Id=");
- String id=Input.nextLine();
- System.out.print("Student CGPA=");
- double cgpa= Input.nextDouble();
- Input.nextLine();
- System.out.print("Teacher name=");
- String name1=Input.nextLine();
- System.out.print("Teacher Age=");
- int age1=Input.nextInt();
- Input.nextLine();
- System.out.print("Teacher designation=");
- String designation=Input.nextLine();
- System.out.print("Teacher dept=");
- String dept=Input.nextLine();
- System.out.print("deptName=");
- String deptName = Input.next();
- System.out.print("deptCode=");
- int deptCode = Input.nextInt();
- obj1[i]=new Student(name,age,id,cgpa);
- System.out.println("Student Information\n");
- obj1[i].display();
- obj2[i]=new Teacher(name1,age1,designation,dept);
- System.out.println("Teacher Information\n");
- obj2[i].display();
- obj[i] = new Department(deptName,deptCode,obj1[i],obj2[i]);
- System.out.println("All Informatin\n");
- obj[i].displayAll();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement