🎓 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 (178K+ 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.0Step 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;Conclusion
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment