📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Whether managing a large company or running a small business, salary calculation is a recurring task. In this guide, we'll walk beginners through the process of building a simple Java program to compute the salary of an employee.
Components of Salary
For the purpose of our demonstration, we'll consider the following components while calculating the salary:
Basic Salary: The foundational amount.
HRA (House Rent Allowance): Typically a percentage of the basic salary.
DA (Dearness Allowance): Again, usually a percentage of the basic.
Tax Deduction: A certain percentage deducted from the gross salary (Basic + HRA + DA).
Java Program to Calculate Salary of an Employee
import java.util.Scanner; public class EmployeeSalaryCalculator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter Basic Salary of the Employee:"); double basic = scanner.nextDouble(); double hra = 0.10 * basic; // 10% of basic double da = 0.08 * basic; // 8% of basic double grossSalary = basic + hra + da; double tax = 0.05 * grossSalary; // 5% tax on gross salary double netSalary = grossSalary - tax; System.out.println("Employee Salary Breakdown:"); System.out.println("Basic: " + basic); System.out.println("HRA: " + hra); System.out.println("DA: " + da); System.out.println("Gross Salary: " + grossSalary); System.out.println("Tax Deduction: " + tax); System.out.println("Net Salary: " + netSalary); } }
Output:
Enter Basic Salary of the Employee:25000 Employee Salary Breakdown: Basic: 25000.0 HRA: 2500.0 DA: 2000.0 Gross Salary: 29500.0 Tax Deduction: 1475.0 Net Salary: 28025.0
Step by Step Explanation:
Scanner scanner = new Scanner(System.in); System.out.println("Enter Basic Salary of the Employee:"); double basic = scanner.nextDouble();
double hra = 0.10 * basic; // 10% of basic double da = 0.08 * basic; // 8% of basic
double grossSalary = basic + hra + da;
double tax = 0.05 * grossSalary; // 5% tax on gross salary double netSalary = grossSalary - tax;
Comments
Post a Comment
Leave Comment