Object oriented programming with subclasses Essay

Inheritance & A ; Polymorphism

Given Person category definition below:

category Person {

private String name ;

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!

order now

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 case of Student has a category position ( fresher, sophomore, junior, and senior ) . Declare the position as invariables in the Student category. An case of Employee has a section, salary, and date-hired. Specify a category named MyDate that contains Fieldss of the twelvemonth, month, and twenty-four hours. A module member has office hours and a rank ( lector, senior lector, associate professor, and professor ) . A staff member has a place rubric. Override the toString ( ) method in

  • Person category to expose the category name and the individual ‘s name.
  • Student category to expose category name, pupil ‘s name and category position.
  • Employee category to expose category name, employee ‘s name, and section
  • Faculty category to expose category name, employee ‘s name, office hours and rank
  • Staff category to expose category name, employee ‘s name, place rubric

  1. Pull a category diagram to stand for the relationship of the categories above.
  2. Using Java to compose and implement the categories with respect to the category diagram.
  3. Write a trial plan in Java that creates cases of Person, Student, Employee, Faculty, and Staff, and raise their toString ( ) method.
  4. Write another trial plan in Java that creates cases of Person, Student, Employee, Faculty, and Staff in an array of Object. Use a repeat statement to name its toString ( ) method.

  • Modify the categories in inquiry ( 1 ) above:
    1. Add a bundle ctb2209.p7 to Person category, and so roll up all the categories once more. Explain the mistakes and repair it.

  • Design a category named Square that contains informations Fieldss for tallness, breadth, and an abstract method named computeSurfaceArea ( ) . Make a child category named Cube. Cube contains an extra informations field named deepness, and overrides computeSurfaceArea ( ) method inherited from its parent method.
    1. Implement all the categories.
    2. Write an application that instantiates objects of Square and Cube in an array and displays the surface countries of each object utilizing loop, and test all the methods of all the objects.
    3. Create an abstract AutoMobile category with Fieldss for the auto brand and monetary value. Include get and put methods for these Fieldss ; the calculatePrice ( ) method is abstract. Make two subclasses for single car shapers ( for illustration, Ford or Honda ) , and include appropriate calculatePrice ( ) method in each subclass ( for illustration, RM110,000 or RM120,000 severally ) .

  • Finally, compose an application that uses the AutoMobile category as mention type and instantiate objects of its subclasses to expose information about different autos. Salvage the files as AutoMobile.java, Ford.java, Honda.java and UseAutoMobile.java.
  • Create an interface called Player. The interface has an abstract method called drama ( ) that displays a message depicting the significance of “ drama ” to the category. Create categories called Child, Musician, and Actor that implement Player interface. Create an application that demonstrates the usage of the categories. Salvage the files as Player.java, Child.java, Actor.java, Musician.java, and UsePlayer.java.
  • Sunway Construction Loan Corporate makes loans of up to RM100,000,000,000 for building undertakings. There are two classs of Loans – those to concerns and those to single appliers.

  • Write an application that tracks all new building loans. The application must besides cipher the entire sum owed at the due day of the month ( original loan sum + loan fee ) . The application should include the undermentioned categories:
    • LoanConstants – A public interface category. LoanConstants includes changeless values for short-run ( one twelvemonth ) , medium-term ( three old ages ) , and long-run ( five old ages ) loans. It besides contains invariables for the company name and the maximal loan sum.
    • Loan – A public abstract category that implements the LoanConstants interface. A Loan includes a loan figure, client last name, sum of loan, involvement rate, and term. The builder requires informations for each of the Fieldss except involvement rate. Make non let loan sums over RM100,000,000,000. Force any loan term that is non one of the three defined in the LoanConstants category to a short-run ( annual ) loan. Make a toString ( ) method that displays all the loan informations.
    • BusinessLoan – A public category that extends Loan. The BusinessLoan builder sets the involvement rate to 1 % over the current basic involvement rate.
    • PersonalLoan – A public category that extends Loan. The PersonalLoan builder sets the involvement rate to 2 % over the current basic involvement rate.
    • CreateLoans – An application that creates an array of five Loans. Motivate that user for the current basic involvement rate. Then, in a cringle, motivate the user for a loan type and all relevant information for that loan. Store the created Loan objects in the array. When informations entry is complete, expose all the loans.

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

    [ Note: java.util.Date and java.text.SimpleDateFormat may necessitate for your entire sum owed at the due day of the month computation, you may look at the use of format ( ) and parse ( ) methods of SimplateDateFormat category ]