📘 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.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
In any professional environment, understanding the components that make up an employee's salary is crucial. The gross salary is the sum total of the basic salary along with any additional allowances before any deductions. In this guide, we will explore how to compute the gross salary of an employee using a simple Java program.
Components of Salary
For our program, the gross salary will consist of:
Basic Salary: The foundational pay.
HRA (House Rent Allowance): Typically a percentage of the basic salary.
DA (Dearness Allowance): Another percentage of the basic salary.
Java Program to Calculate Gross Salary of Employee
import java.util.Scanner;
public class GrossSalaryCalculator {
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;
System.out.println("Employee Gross Salary Breakdown:");
System.out.println("Basic: " + basic);
System.out.println("HRA: " + hra);
System.out.println("DA: " + da);
System.out.println("Gross Salary: " + grossSalary);
}
}
Output:
Enter Basic Salary of the Employee:
10000
Employee Gross Salary Breakdown:
Basic: 10000.0
HRA: 1000.0
DA: 800.0
Gross Salary: 11800.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;
System.out.println("Employee Gross Salary Breakdown:");
System.out.println("Basic: " + basic);
System.out.println("HRA: " + hra);
System.out.println("DA: " + da);
System.out.println("Gross Salary: " + grossSalary);
Comments
Post a Comment
Leave Comment