Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone_number, and e-mail address. A student has a status (freshman, sophomore, junior, or senior). An employee has an office, salary. A faculty member has office_hours and a rank. A staff member has a title. Override the toString() method in each of these classes to display their details. Write a Java application and subsequent pseudocode to implement/simulate the same.
Question
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone_number, and e-mail address. A student has a status (freshman, sophomore, junior, or senior). An employee has an office, salary. A faculty member has office_hours and a rank. A staff member has a title. Override the toString() method in each of these classes to display their details. Write a Java application and subsequent pseudocode to implement/simulate the same.
Solution
Here is the Java code for the classes:
public class Person {
String name;
String address;
String phoneNumber;
String email;
@Override
public String toString() {
return "Person [name=" + name + ", address=" + address + ", phoneNumber=" + phoneNumber + ", email=" + email + "]";
}
}
public class Student extends Person {
String status;
@Override
public String toString() {
return "Student [status=" + status + ", name=" + name + ", address=" + address + ", phoneNumber=" + phoneNumber + ", email=" + email + "]";
}
}
public class Employee extends Person {
String office;
double salary;
@Override
public String toString() {
return "Employee [office=" + office + ", salary=" + salary + ", name=" + name + ", address=" + address + ", phoneNumber=" + phoneNumber + ", email=" + email + "]";
}
}
public class Faculty extends Employee {
String officeHours;
String rank;
@Override
public String toString() {
return "Faculty [officeHours=" + officeHours + ", rank=" + rank + ", office=" + office + ", salary=" + salary + ", name=" + name + ", address=" + address + ", phoneNumber=" + phoneNumber + ", email=" + email + "]";
}
}
public class Staff extends Employee {
String title;
@Override
public String toString() {
return "Staff [title=" + title + ", office=" + office + ", salary=" + salary + ", name=" + name + ", address=" + address + ", phoneNumber=" + phoneNumber + ", email=" + email + "]";
}
}
And here is the pseudocode:
class Person
data: name, address, phoneNumber, email
method toString: return name, address, phoneNumber, email
class Student extends Person
data: status
method toString: return status, name, address, phoneNumber, email
class Employee extends Person
data: office, salary
method toString: return office, salary, name, address, phoneNumber, email
class Faculty extends Employee
data: officeHours, rank
method toString: return officeHours, rank, office, salary, name, address, phoneNumber, email
class Staff extends Employee
data: title
method toString: return title, office, salary, name, address, phoneNumber, email
In the Java code, each class has its own data fields and a toString method that returns a string representation of the object. The toString method is overridden in each subclass to include the data fields of the superclass and the subclass. The pseudocode follows the same structure as the Java code.
Similar Questions
21. Write a Java program that creates a class hierarchy for employees of a company. The base class should be Employee, with subclasses Manager, Developer, and Programmer. Each subclass should have properties such as name, address, salary, and job title. Implement methods for calculating bonuses, generating performance reports, and managing projects
Construct a class Person with attributes name, age, address and a methoddisplay() to display the details. Create a subclass Student with attributesrollno, mark1, mark2, and mark3. Override display() method and calculatethe grade. Create another subclass Faculty with attributes faculty_id,department, basic_pay and DA. Override display() method to calculate totalsalary as (basic_pay + DA) + 70% of (basic_pay + DA). Create instances ofStudent and Faculty and display the details
Write a java program to define a class Person having name of the person , age of the person and gender of the person. Include accept() and toString() method to display the data. Create 3 objects and display name of the person who is youngest
[25 points] Write a Java class named Employee such that the class contains threeattributes empName, salary, and departmentName. You should be able to createobjects of this class by supplying values to any one, two, or all three of the attributes. Ifno value is supplied during the object creation, the attributes should be initialized withsome default values. You are expected to use 'this' keyword to achieve the result. Discussthe ways in which you can change or reset the attribute values of the objects created.Write appropriate mutator methods that store values in these fields and accessormethods that return the values in these fields. Once you have written the class, write aseparate program that creates three Employee objects to hold the following data:Employee Name Department Salary---------------------------------------------------------------------Susan Meyers Accounting 5000.00Mark Jones IT 8375.00Joy Rogers Manufacturing 6380.00---------------------------------------------------------------------The program should store this data in the three objects and then display the data for eachemployee on the screen
Develop a Java program to add student’s names and display it using vectorclass.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.