Hello, this is my first question on Cramster. Create a Faculty subclass of Emplo
ID: 3640813 • Letter: H
Question
Hello, this is my first question on Cramster.
Create a Faculty subclass of Employee which has the additional data of rank and expertise. Rank could be one of Assistant Professor, Associate Professor, or Professor. Expertise would be a String such as Computer Science, Music, History etc.
Create a Staff subclass of Employee which has the additional data of Category (Full or Part time). Provide suitable constructors for your classes. Each of these sub classes must have a change_status() method that changes the rank or category respectively. For example, an Associate Professor could be promoted to Professor; a Full time classified could be demoted to part time. Add a change_status() method to the Employee base class that simply outputs a message “Cannot change this Employee’s status”.
Demonstrate dynamic binding in your main program. Declare an array of Employees (compile time type) but assign different subclasses to each array element (run time type). Show that get_info() and change_status() uses the methods determined by their run time types and displays all the relevant data.
Explanation / Answer
public class Faculty { //CONSTANTS public final static int ASSISTANT_PROFESSOR = 0; public final static int ASSOCIATE_PROFESSOR = 1; public final static int PROFESSOR = 2; //ATRIBUTES private int rank; private String expertise; //CONSTRUCTORS public Faculty(int pRank, String pExpertise) { rank = pRank; expertise = pExpertise; } //METHODS public void changeRank(int pRank) { rank = pRank; } public void changeExpertise(String pExpertise) { expertise = pExpertise; } public int getRank() { return rank; } public String getExpertise() { return expertise; } } --------------------------------------------------------------------------------------- public class Staff { //CONSTANTS public final static int PART = 0; public final static int FULL = 1; //ATRIBUTES private int category; //CONSTRUCTORS public Staff(int pCategory) { category = pCategory; } //METHODS public void changeCategory(int pCategory) { category = pCategory; } public int getCategory() { return category; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.