Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program using inheritance that will allow a user to enter in information

ID: 3825779 • Letter: W

Question

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. After the user has entered in all of their records, print them out in a legible way and ask if they want to enter more information.

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)

Be sure to use inheritance so variables aren’t declared in subclasses if they are not necessary.

Explanation / Answer


//Person.java
public class Person {
   private String name;
   private String address;
   private String email;
  
  
   //Constructor that takes name, address and email as input
   //variables
   public Person(String name, String address, String email) {
      
       this.name=name;
       this.address=address;
       this.email=email;
   }
  
   //Retunrs the person object
   public String toString() {      
       return "Name :"+name
               +" Address :"+address
               +" E-mail:"+email;
   }
}//end of Person class

------------------------------------------------------------------------------------------------------------------------------------

//Faculty.java
public class Faculty extends Person{
  
   private String courseTaught;
   private String department;
   public Faculty(String name, String address, String email,
           String courseTaught,String department) {
       //calling super class constructor
       super(name, address, email);
       this.courseTaught=courseTaught;
       this.department=department;
   }
  

   public String toString() {      
       return super.toString()+
               " Course taught : "+courseTaught
               +" Department : "+department;
   }

}

------------------------------------------------------------------------------------------------------------------------------------


//Staff.java
public class Staff extends Person{

   private String department;
   private String title;
   public Staff(String name, String address, String email,
           String department, String title) {
       //calling super class person constructor
       super(name, address, email);
       this.department=department;
       this.title=title;
   }
  

   public String toString() {
      
       return super.toString()              
               +" Department : "+department
               +" Title :"+title;
   }
}

------------------------------------------------------------------------------------------------------------------------------------

//Advisor.java
public class Advisor extends Person{

   private String department;
   private String position;
  
   public Advisor(String name, String address, String email,
           String department, String position) {
       //calling super classs Person constructor
       super(name, address, email);
       this.department=department;
       this.position=position;
   }
  

   public String toString() {      
       return super.toString()
               +" Department : "+department
               +" Position :"+position;
   }
  
}

------------------------------------------------------------------------------------------------------------------------------------


//UnderGraduate.java
public class UnderGraduate extends Graduate{  
   public UnderGraduate(String name, String address, String email,
           int year, double gpa) {
       //Calling super class Person
       //constructor
       super(name, address, email, year, gpa);      
   }  
   //Returns string representation of UnderGraduate
   public String toString() {      
       return super.toString();
   }
}

------------------------------------------------------------------------------------------------------------------------------------

//Graduate.java
public class Graduate extends Person{  
   private int year;
   private double gpa;
  
   public Graduate(String name, String address, String email,
           int year, double gpa) {
       //Calling super class Person
       //constructor
       super(name, address, email);
       this.year=year;
       this.gpa=gpa;      
   }
  
   /*Returns the string representation
      of Graduate */
   public String toString() {
      
       return super.toString()+
               " Year : "+year+
               " Gpa : "+gpa;
   }
  
  
}

------------------------------------------------------------------------------------------------------------------------------------


//Driver.java
public class Driver {
   public static void main(String[] args) {
      
      
       //Create an instnace of Faculty
       Faculty faculty=new Faculty("Mark","Down-town,NY" ,
           "mark[at]au.com", "CS100", "ComputerScience");
      
       System.out.println("Faculty");
       System.out.println(faculty);
      
      
       //Create an instnace of staff
       Staff staff=new Staff("Singh", "Duck-Line,NW", "singh[at]mai.com",
               "Admin", "Cheif");
      
       System.out.println("Staff");
       System.out.println(staff.toString());
      
      
       //Create an instnace of advisor
       Advisor advisor=new Advisor("karan", "Duck-Line,NW", "karan[at]mai.com",
               "Recruitment", "HRManager");
      
       System.out.println("Advisor");
       System.out.println(advisor.toString());
      
      
       //Create an instnace of UnderGraduate
       UnderGraduate ugraduage=new UnderGraduate
               ("Micheal", "NY,US", "micheal[at]mail.com",
               2012,5.0) ;
       System.out.println("Under-Graduage");
       System.out.println(ugraduage.toString());
      
       //Create an instnace of Graduate
       Graduate graduate=new Graduate
               ("Isha", "NY,US", "isha[at]mail.com",
               2014,4.0) ;
       System.out.println("Graduage");
       System.out.println(graduate.toString());
      
   }

}

------------------------------------------------------------------------------------------------------------------------------------

Sample output:

Faculty
Name :Mark
Address :Down-town,NY
E-mail:mark[at]au.com
Course taught : CS100
Department : ComputerScience
Staff
Name :Singh
Address :Duck-Line,NW
E-mail:singh[at]mai.com
Department : Admin
Title :Cheif
Advisor
Name :karan
Address :Duck-Line,NW
E-mail:karan[at]mai.com
Department : Recruitment
Position :HRManager
Under-Graduage
Name :Micheal
Address :NY,US
E-mail:micheal[at]mail.com
Year : 2012
Gpa : 5.0
Graduage
Name :Isha
Address :NY,US
E-mail:isha[at]mail.com
Year : 2014
Gpa : 4.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote