Object oriented programming with subclasses


This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

Inheritance & Polymorphism

Given Person class definition below:

class Person {

private String name;

Person(String name) {

this.name = name;


public String getName() {

return name;



  1. Design two subclasses of Person, named Student and Employee. Make Faculty and Staff subclasses of Employee. An instance of Student has a class status (freshman, sophomore, junior, and senior). Declare the status as constants in the Student class. An instance of Employee has a department, salary, and date-hired. Define a class named MyDate that contains fields of the year, month, and day. A faculty member has office hours and a rank (lecturer, senior lecturer, associate professor, and professor). A staff member has a position title. Override the toString() method in

    • Person class to display the class name and the person's name.
    • Student class to display class name, student's name and class status.
    • Employee class to display class name, employee's name, and department
    • Faculty class to display class name, employee's name, office hours and rank
    • Staff class to display class name, employee's name, position title

    1. Draw a class diagram to represent the relationship of the classes above.
    2. Using Java to write and implement the classes with regard to the class diagram.
    3. Write a test program in Java that creates instances of Person, Student, Employee, Faculty, and Staff, and invokes their toString() method.
    4. Write another test program in Java that creates instances of Person, Student, Employee, Faculty, and Staff in an array of Object. Use a repetition statement to call its toString() method.

  2. Modify the classes in question (1) above:

    1. Add a package ctb2209.p7 to Person class, and then compile all the classes again. Explain the errors and fix it.

  3. Design a class named Square that contains data fields for height, width, and an abstract method named computeSurfaceArea(). Create a child class named Cube. Cube contains an additional data field named depth, and overrides computeSurfaceArea() method inherited from its parent method.

    1. Implement all the classes.
    2. Write an application that instantiates objects of Square and Cube in an array and displays the surface areas of each object using iteration, and test all the methods of all the objects.
    3. Create an abstract AutoMobile class with fields for the car make and price. Include get and set methods for these fields; the calculatePrice() method is abstract. Create two subclasses for individual automobile makers (for example, Ford or Honda), and include appropriate calculatePrice() method in each subclass (for example, RM110,000 or RM120,000 respectively).

  4. Finally, write an application that uses the AutoMobile class as reference type and instantiate objects of its subclasses to display information about different cars. Save the files as AutoMobile.java, Ford.java, Honda.java and UseAutoMobile.java.

  5. Create an interface called Player. The interface has an abstract method called play() that displays a message describing the meaning of "play" to the class. Create classes called Child, Musician, and Actor that implement Player interface. Create an application that demonstrates the use of the classes. Save the files as Player.java, Child.java, Actor.java, Musician.java, and UsePlayer.java.
  6. Sunway Construction Loan Corporate makes loans of up to RM100,000,000,000 for construction projects. There are two categories of Loans - those to businesses and those to individual applicants.

  7. Write an application that tracks all new construction loans. The application must also calculate the total amount owed at the due date (original loan amount + loan fee). The application should include the following classes:

    • LoanConstants - A public interface class. LoanConstants includes constant values for short-term (one year), medium-term (three years), and long-term (five years) loans. It also contains constants for the company name and the maximum loan amount.
    • Loan - A public abstract class that implements the LoanConstants interface. A Loan includes a loan number, customer last name, amount of loan, interest rate, and term. The constructor requires data for each of the fields except interest rate. Do not allow loan amounts over RM100,000,000,000. Force any loan term that is not one of the three defined in the LoanConstants class to a short-term (one-year) loan. Create a toString() method that displays all the loan data.
    • BusinessLoan - A public class that extends Loan. The BusinessLoan constructor sets the interest rate to 1% over the current basic interest rate.
    • PersonalLoan - A public class that extends Loan. The PersonalLoan constructor sets the interest rate to 2% over the current basic interest rate.
    • CreateLoans - An application that creates an array of five Loans. Prompt that user for the current basic interest rate. Then, in a loop, prompt the user for a loan type and all relevant information for that loan. Store the created Loan objects in the array. When data entry is complete, display all the loans.

    Save the files as Loan.java, LoanConstants.java, BusinessLoan.java, PersonalLoan.java, and CreateLoans.java.

[Note: java.util.Date and java.text.SimpleDateFormat may needed for your total amount owed at the due date calculation, you may look at the usage of format() and parse() methods of SimplateDateFormat class]

Writing Services

Essay Writing

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.