Question

In: Computer Science

in java Design and implement a class named Person and its two subclasses named Student and...

in java

Design and implement 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 email address. A student has a class status (year 1,year 2,year 3,or year 4). An employee has an office, salary, and date hired. Use the Date class from JavaAPI 8 to create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name.Design and implement all 5classes. Write a test program that creates a Person,Student,Employee,Faculty, and Staff, and iinvokes their toString()methods

Solutions

Expert Solution

Answer:

Driver class has all the objects from the mentioned classes, all you need is to execute this class.

import java.time.LocalDate;

public class TestManyClasses {
public static void main(String[] args){
// Person object
Person person = new Person();
person.setName("Adams");
person.setAddress("Eire Island");
person.setEmailId("[email protected]");
person.setPhoneNumber("9809999999");
System.out.println("The person object: \n" + person);

// student object
Student student = new Student();
student.setName("Adams Paul");
student.setAddress("University Of Texas");
student.setEmailId("[email protected]");
student.setPhoneNumber("9809999999");
student.setClass(Student.Status.year_1);
System.out.println("Student object : \n" + student);

// employee object
Employee employee = new Employee();
employee.setName("Christina Kerr");
employee.setAddress("St Peter's Street, California");
employee.setOffice("Google Inc");
employee.setSalary(100000);
employee.setEmailId("[email protected]");
employee.setPhoneNumber("9991919191");
employee.setDateHired(LocalDate.of(2010, 2, 14));
System.out.println("The employee object : \n" + employee);

// The faculty object
Faculty faculty = new Faculty();
faculty.setName("Albert");
faculty.setOfficeHours(10);
faculty.setOffice("Dallas");
faculty.setRank(1);
faculty.setDateHired(LocalDate.of(2009, 5, 10));
faculty.setAddress("Peters Burg");
faculty.setPhoneNumber("9080898984");
faculty.setSalary(1006033);
System.out.println("The faculty object: \n" +faculty);

// The staff object
Staff staff = new Staff();
staff.setName("Christopher");
staff.setTitle("Asst Prof");
staff.setAddress("Washington DC");
staff.setDateHired(LocalDate.of(2012, 5, 19));
staff.setEmailId("[email protected]");
staff.setOffice("Main branch");
staff.setPhoneNumber("9898925923");
staff.setSalary(15000);
System.out.println("The staff object : \n" + staff);
}
}

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

public class Person {

// attributes
private String name;
private String address;
private String phoneNumber;
private String emailId;

// getters & setters
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String getEmailId() {
return emailId;
}

public void setEmailId(String emailId) {
this.emailId = emailId;
}

@Override
public String toString() {
return "Person{" +
" name='" + name + '\'' +
", address='" + address + '\'' +
", phoneNumber=" + phoneNumber +
", emailId='" + emailId + '\'' +
'}';
}
}

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

import java.time.LocalDate;

public class Employee extends Person{

// office, salary, and date hired
private String office;
private float salary;
private LocalDate dateHired;

// getter & setters
public String getOffice() {
// returns the office value
return office;
}

public void setOffice(String office) {
// setter for office
this.office = office;
}

public float getSalary() {
// getter for salary
return salary;
}

public void setSalary(float salary) {
// setter for salary
this.salary = salary;
}

public LocalDate getDateHired() {
// getter for date hired
return dateHired;
}

public void setDateHired(LocalDate dateHired) {
// setter for date hired
this.dateHired = dateHired;
}

@Override
public String toString() {
// Overridden method for toString, change accordingly
return "Employee{" +
" name='" + super.getName() + '\'' +
", address='" + super.getAddress() + '\'' +
", phoneNumber=" + super.getPhoneNumber() +
", emailId='" + super.getEmailId() + '\'' +
" office='" + office + '\'' +
", salary=" + salary +
", dateHired=" + dateHired +
'}';
}
}

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

public class Faculty extends Employee{

    // office hours and a rank
    private float officeHours;
    private int rank;

    public float getOffice_hours() {
        // getter for office hours
        return officeHours;
    }

    public void setOfficeHours(float officeHours) {
        // setter for office hours
        this.officeHours = officeHours;
    }

    public int getRank() {
        // getter for rank
        return rank;
    }

    public void setRank(int rank) {
        // setter for rank
        this.rank = rank;
    }

    @Override
    public String toString() {
        // change the overridden method accordingly
        return "Faculty{" +
                "  name='" + super.getName() + '\'' +
                ", address='" + super.getAddress() + '\'' +
                ", phoneNumber=" + super.getPhoneNumber() +
                ", emailId='" + super.getEmailId() + '\'' +
                "  office='" + super.getOffice() + '\'' +
                ", salary=" + super.getSalary() +
                ", dateHired=" + super.getDateHired() +
                "  officeHours=" + officeHours +
                ", rank=" + rank +
                '}';
    }
}

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

public class Staff extends Employee{
private String title;

public String getTitle() {
// getter for title
return title;
}

public void setTitle(String title) {
// setter for title
this.title = title;
}

@Override
public String toString() {
// The toString() method overridden, change accordingly
return "Staff{" +
" name='" + super.getName() + '\'' +
", address='" + super.getAddress() + '\'' +
", phoneNumber=" + super.getPhoneNumber() +
", emailId='" + super.getEmailId() + '\'' +
" office='" + super.getOffice() + '\'' +
", salary=" + super.getSalary() +
", dateHired=" + super.getDateHired() +
" title='" + title + '\'' +
'}';
}
}
-------------------------------------------------------------------------------

public class Student extends Person{
private Status studentClass;
enum Status { // decides on the class/status of the student
year_1,
year_2,
year_3,
year_4
}

public void setClass(Status status){
this.studentClass = status;
}

@Override
public String toString() {
//return "Student class : " + studentClass;
return "Student {" +
" name='" + super.getName() + '\'' +
", address='" + super.getAddress() + '\'' +
", phoneNumber=" + super.getPhoneNumber() +
", emailId='" + super.getEmailId() + '\'' +
" class/status : " + studentClass +
'}';
}

}

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

Output for your reference


Related Solutions

Java Question Design a class named Person and its two subclasses named Student and Employee. Make...
Java 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 email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the Date class to create an object for date hired. A faculty member has office hours and a rank. A...
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and...
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 class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to...
JAVA Design a class named Person and its two derived classes named Student and Employee. Make...
JAVA Design a class named Person and its two derived classes named Student and Employee. Make Faculty and Staff derived classes of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). An employee has an office, salary, and datehired. Define a class named MyDate that contains the fields year, month, and day. A faculty member has office hours and a rank. A staff member has a...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement the compareTo method to compare the triangles on the basis of similarity. Draw the UML diagram for your classes. Write a Driver class (class which instantiates the comparableTriangle objects) to determine if two instances of ComparableTriangle objects are similar (sample output below). It should prompt the user to enter the 3 sides of each triangle and then display whether or not the are similar...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
JAVA Implement a public class method named comparison on a public class Compare that accepts two...
JAVA Implement a public class method named comparison on a public class Compare that accepts two Object arguments. It should return 0 if both references are equal. 1 if both objects are equal. and -1 otherwise. (SUPER IMPORTANT) Either reference can be null, so you'll need to handle those cases carefully! Here is what I have so far: public class Compare { public static int comparison(Object a, Object b) {   if (a == null || b == null) {    return...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
Design and develop a class named Person in Python that contains two data attributes that stores...
Design and develop a class named Person in Python that contains two data attributes that stores the first name and last name of a person and appropriate accessor and mutator methods. Implement a method named __repr__ that outputs the details of a person. Then Design and develop a class named Student that is derived from Person, the __init__ for which should receive first name and last name from the class Person and also assigns values to student id, course, and...
In Java, design a class named MyInteger. The class contains: An int data field named value...
In Java, design a class named MyInteger. The class contains: An int data field named value that stores the int value represented by this object. A constructor that creates a MyInteger object for the specified int A get method that returns the int Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively. Static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively. Static...
This is 1 java question with its parts. Thanks so much! Create a class named Student...
This is 1 java question with its parts. Thanks so much! Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT