Employee Hierarchy in Java: Explanation & Practice

Create an employee class hierarchy

Problem summary

Create Employee base class with Manager and Developer subclasses. Each has different bonus calculation.

Starter code

// Employee: name, baseSalary, abstract getBonus()
// Manager: 20% bonus
// Developer: 15% bonus

public class Main {
    public static void main(String[] args) {
        // Test case 1: Manager with 80000 salary
        // Print: Total salary: <base + bonus>
    }
}

Expected output and test cases

  • Manager 80000 + 20%
    Total salary: 96000.0
  • Developer 50000 + 15%
    Total salary: 57500.0
  • Manager 50000 base
    Total salary: 60000.0

Hints

  1. Abstract method getBonus() in base
  2. Each subclass calculates differently
  3. Total = base + getBonus()

Related Inheritance exercises

Practice all Inheritance exercises · Run this idea in the Java compiler