Need in Java Write a program using inheritance that will all
Need in Java
Write a program using inheritance that will allow a user to enter in information for various types of people at a university. The program should allow the user to enter information about Faculty Members, Staff Members, Students, Advisors, and an Other type to catch all others.
The hierarchy of the classes should be as follows, or at least similar.
Person (name, address, email, etc)
Employee
Faculty (courses taught, department, etc)
Staff (department, title, etc)
Advisor (department, position outside of university, etc)
Student
Undergraduate Student (class year, gpa, etc)
Graduate Student (same as undergrad)
Other (role at university, position outside of university, etc)
The program should decide what information is necessary for each type. I’ve included some examples in parenthesis next to the class name, but think about what other information may be pertinent to the university.
Be sure to use inheritance so variables aren’t declared in subclasses if they are not necessary.
After the user has entered in all of their records, print them out in a legible way.
Solution
package com.university;
public class Person {
String name;
String address;
String email;
public void personInfo(String name,String address,String email){
this.name=name;
this.address=address;
this.email=email;
System.out.println(\"Person Name: \"+name);
System.out.println(\"Person Address: \"+address);
System.out.println(\"Person Email: \"+email);
}
}
package com.university;
public class Employee extends Person {
String courses_taught;
String department;
String title;
String position_outside_of_university;
public void facultyInfo(String courses_taught,String department){
this.courses_taught=courses_taught;
this.department=department;
System.out.println(\"Facuty courses_taught : \"+courses_taught);
System.out.println(\"Facuty department : \"+department);
}
public void staffInfo(String department, String title){
this.department=department;
this.title=title;
System.out.println(\"Staff department : \"+department);
System.out.println(\"Staff title : \"+title);
}
public void advisorInfo(String department,String position_outside_of_university){
this.department=department;
this.position_outside_of_university=position_outside_of_university;
System.out.println(\"Advisor department: \"+department);
System.out.println(\"Advisor position_outside_of_university: \"+position_outside_of_university);
}
}
package com.university;
public class Student extends Employee{
String class_year;
Double gpa;
public void undergraduate_StudentInfo(String class_year,Double gpa){
this.class_year=class_year;
this.gpa=gpa;
System.out.println(\"undergraduate Student class_year: \"+class_year);
System.out.println(\"undergraduate Student gpa: \"+gpa);
}
public void graduate_StudentInfo(String class_year,Double gpa){
this.class_year=class_year;
this.gpa=gpa;
System.out.println(\"Graduate Student class_year: \"+class_year);
System.out.println(\"Graduate Student gpa: \"+gpa);
}
}
package com.university;
public class Other extends Student {
String role_at_university;
String position_outside_of_university;
public void otherInfo(String role_at_university,String position_outside_of_university){
this.role_at_university=role_at_university;
this.position_outside_of_university=position_outside_of_university;
System.out.println(\"Role_at_university: \"+role_at_university);
System.out.println(\"Position_outside_of_university: \"+position_outside_of_university);
}
}
This is test program to test all above code.
package com.university;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
//int a=0;
Other o=new Other();
while(true){
Scanner sc=new Scanner(System.in);
System.out.println(\"Enter Preson Name\");
String name=sc.next();
System.out.println(\"Enter Preson Address\");
String address=sc.next();
System.out.println(\"Enter Preson Email\");
String email=sc.next();
o.personInfo(name, address, email);
System.out.println(\"Enter 1 for Employee and 2 for Student\");
int a=sc.nextInt();
if(a==1){
Scanner sc1=new Scanner(System.in);
System.out.println(\"Enter 1 for Faculty, 2 for Staff and 3 for advisor\");
int b=sc1.nextInt();
if(b==1){
Scanner sc2=new Scanner(System.in);
System.out.println(\"Enter Faculty courses_taught\");
String courses_taught =sc1.next();
System.out.println(\"Enter Faculty department\");
String department =sc1.next();
o.facultyInfo(courses_taught, department);
}else if(b==2){
//Scanner sc2=new Scanner(System.in);
System.out.println(\"Enter Staff department\");
String department =sc1.next();
System.out.println(\"Enter Staff title\");
String title =sc1.next();
o.staffInfo(department, title);
}else{
//Scanner sc2=new Scanner(System.in);
System.out.println(\"Enter advisor department\");
String department =sc1.next();
System.out.println(\"Enter advisor position_outside_of_university\");
String position_outside_of_university =sc1.next();
o.advisorInfo(department, position_outside_of_university);
}
}else{
Scanner sc3=new Scanner(System.in);
System.out.println(\"Enter 1 for Undergraduate and 2 for Graduate Student \");
int c=sc3.nextInt();
if(c==1){
System.out.println(\"Enter undergraduate_Student class_year\");
String class_year =sc3.next();
System.out.println(\"Enter undergraduate_Student gpa\");
double gpa =sc3.nextDouble();
o.undergraduate_StudentInfo(class_year, gpa);
}else{
System.out.println(\"Enter graduate_Student class_year\");
String class_year =sc3.next();
System.out.println(\"Enter graduate_Student gpa\");
double gpa =sc3.nextDouble();
o.graduate_StudentInfo(class_year, gpa);
}
}
}
}
}



