PROGRAMMING

Write a java program to compute net pay after deducting tax of 15% from the gross pay

Write a java program to compute net pay after deducting tax of 15% from the gross pay. Write a program to implement Employee class having fields as empno and basicpay, and methods for the following:

(i) compute Gross pay (receives hra% and da% as parameters and computes gross pay as basic + basic hra% + basic*da%).

(ii) compute net pay after deducting tax of 15% from the gross pay.

(iii) display the payslip

The code for : Write a java program to compute net pay after deducting tax of 15% from the gross pay.

import java.util.*;
class Employee
{
static int empNo;
static double grossP,basic,netpay;
static Scanner in=new Scanner(System.in);
public static void Gp(double hra,double da)
{
grossP=basic + (basic*(hra/100))+(basic*(da/100));
}
public static void NetPay()
{
netpay=grossP - (grossP*(15.0/100));
}
public static void display()
{
System.out.println("Emplyee no. "+empNo);
System.out.println("Gross Pay "+grossP);
System.out.println("Net Pay "+netpay);
}

public static void main()
{
System.out.println("Enter employee No. ");
empNo=in.nextInt();
System.out.println("Enter basic pay ");
basic=in.nextDouble();
System.out.println("Enter HRA% and DA%");
double h=in.nextDouble(),d=in.nextDouble();
Gp(h,d);
NetPay();
display();
}
}

In this post we have shared a java program which is mostly asked by students of computer science.

Explaining the code:

The provided Java code defines a class named Employee with static variables and methods for calculating gross pay, net pay, and displaying employee information. The class includes methods for computing gross pay (Gp) based on provided house rent allowance (HRA) and dearness allowance (DA) percentages, calculating net pay after deducting a fixed tax rate of 15%, and displaying employee details including employee number, gross pay, and net pay.

In the main method, it prompts the user to input employee number, basic pay, HRA percentage, and DA percentage. Then, it calculates gross pay using the provided allowances and basic pay, followed by computing net pay by deducting tax. Finally, it displays the employee’s details including the employee number, gross pay, and net pay.

This code snippet demonstrates basic concepts of Java programming, including class definition, static methods, user input using Scanner, mathematical calculations, and output display. However, it could be enhanced by incorporating encapsulation, error handling for invalid inputs, and clearer variable names to improve readability and maintainability. Additionally, separating concerns into different classes, such as Employee and PayCalculator, would enhance code organization and scalability.

THANK YOU FOR VISITING OUR BLOG. For more related posts and anime, programing, gaming post please regularly check our blog.

THANK YOU!!!!!!!!!!!!

Lavi Thakur

Recent Posts

How to make money as a Beginner Coder in 2025

Making money as a coder in 2025 is not much of a big or tough…

8 months ago

Lloyds Technology Centre : A Concise Guide

Lloyds Technology Centre, A tech and data company located in Hyderabad, India. They are  part of…

9 months ago

How to Increase Height at Any Age

How to Increase Height at Any Age Rise Above: How to Increase Height at Any…

10 months ago

The Hidden Beauty of Karrukha Wood: A Rare Masterpiece from Nature

In the fast-paced digital world, we often forget the timeless beauty that nature offers. Today,…

10 months ago

Top 10 Deadliest Kicks in Martial Arts [2024]

Top 10 Deadliest Kicks in Martial Arts: Master the Art of Knockouts Martial arts is…

11 months ago

How to Optimize Battery Life of Your Smartphone

How to Optimize Battery Life of Your Smartphone: Tips and Tricks for Prolonging Battery Health…

11 months ago