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.print("Name:"+name+"\nAge:"+age+"\n");
- }
- }
- package class_work;
- public class Teacher extends Person{
- private String designation,dept;
- public Teacher(String name1,int age1,String designation, String dept) {
- super(name1,age1);
- this.designation = designation;
- this.dept = dept;
- }
- public String getDesignation() {
- return designation;
- }
- public String getDept() {
- return dept;
- }
- public void display()
- {
- super.display();
- System.out.println("Designation:"+designation+"\nDepartment"+dept+"\n");
- }
- }
- package class_work;
- public class Student extends Person {
- private String id;
- private double cgpa;
- public Student(String name,int age,String id, double cgpa) {
- super(name,age);
- this.id = id;
- this.cgpa = cgpa;
- }
- public String getId() {
- return id;
- }
- public double getCgpa() {
- return cgpa;
- }
- public void display()
- {
- super.display();
- System.out.println("ID:"+id+"\nCGPA:"+cgpa+"\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 :\nName:"+student.name+"\nAge:"+student.age+"\nID:"+student.getId()+"\nCGPA:"+student.getCgpa()+"\nDepartment:"+depName+"\nDepartment Code:"+depCode+"\n");
- System.out.println("Teacher portal :\nName:"+teacher.name+"\nAge:"+teacher.age+"\nDESIGNATION:"+teacher.getDesignation()+"\nTeacher Department:"+teacher.getDept()+"\nDepartment"+depName+"\nDepartment Code:"+depCode+"\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