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
- Abstract method getBonus() in base
- Each subclass calculates differently
- Total = base + getBonus()
Related Inheritance exercises
- Practice Implementing Interface in Java
- Practice Polymorphism Demo in Java
- Practice Shape Area Calculator in Java
Practice all Inheritance exercises · Run this idea in the Java compiler