Employee Salary Calculator in Java: Explanation & Practice
Calculate employee net salary
Problem summary
Create an Employee class that calculates net salary after tax deductions.
Starter code
// Create Employee class with:
// - String name
// - double grossSalary
// - double getTax() - 10% if <50000, 20% if >=50000
// - double getNetSalary()
public class Main {
public static void main(String[] args) {
// Test case 1: grossSalary = 60000
// Print: Gross: <gross>, Tax: <tax>, Net: <net>
}
}Expected output and test cases
- 20% tax bracket
Gross: 60000.0, Tax: 12000.0, Net: 48000.0
- 10% tax bracket
Gross: 40000.0, Tax: 4000.0, Net: 36000.0
- At threshold
Gross: 50000.0, Tax: 10000.0, Net: 40000.0
Hints
- Check salary against threshold
- Tax = salary * rate
- Net = Gross - Tax
Related OOP Basics exercises
Practice all OOP Basics exercises · Run this idea in the Java compiler