Salary Computation in Java

Download
Download is available until [expire_date]
  • Version
  • Download 267
  • File Size 3.27 KB
  • File Count 1
  • Create Date April 26, 2016
  • Last Updated April 26, 2016

Salary Computation in Java

Compute Salary in Java

This is a sample java program that will compute your salary based on the basic formula
salary = (number of days work * rate per day) – deduction

You are going to input your rate per day, number of days work and deduction to compute the salary.
The program is written in console and gui (graphical user interface) using the swing.

Source code:

import javax.swing.*;
import java.text.*;
class ComputeSalaryGUI {
public static void main(String[] args) {
	
String cont="n";
do
{
double sss=150;
double ph=250;
double pagibig=190;	
double tax=350;	
double deduction;	

String  emp1name, emp1hours, emp1otime, emp1rate;
String  emp2name, emp2hours, emp2otime, emp2rate;	
String  emp3name, emp3hours, emp3otime, emp3rate;
		
double  hourswork1, ot1, rate1, basicsalary1, grosssalary1, netsalary1;
double  hourswork2, ot2, rate2, basicsalary2, grosssalary2, netsalary2;
double  hourswork3, ot3, rate3, basicsalary3, grosssalary3, netsalary3;

emp1name = JOptionPane.showInputDialog(null,"Enter Name Employee 1: ");

emp1hours = JOptionPane.showInputDialog(null,"Enter Hours Work: ");
hourswork1=Double.parseDouble(emp1hours);

emp1otime = JOptionPane.showInputDialog(null,"Enter Overtime pay: ");
ot1=Double.parseDouble(emp1otime);

emp1rate = JOptionPane.showInputDialog(null,"Enter Rate per hour: ");
rate1=Double.parseDouble(emp1rate);

basicsalary1= (rate1 * hourswork1);
deduction=(sss + ph + pagibig + tax);
grosssalary1= basicsalary1 - deduction;
netsalary1=grosssalary1 + ot1;

emp2name = JOptionPane.showInputDialog(null,"Enter Name Employee 2: ");

emp2hours = JOptionPane.showInputDialog(null,"Enter Hours Work: ");
hourswork2=Double.parseDouble(emp2hours);

emp2otime = JOptionPane.showInputDialog(null,"Enter Overtime pay: ");
ot2=Double.parseDouble(emp2otime);

emp2rate = JOptionPane.showInputDialog(null,"Enter Rate per hour: ");
rate2=Double.parseDouble(emp2rate);

basicsalary2= (rate2 * hourswork2);
deduction=(sss + ph + pagibig + tax);
grosssalary2= basicsalary2 - deduction;
netsalary2=grosssalary2 + ot2;

emp3name = JOptionPane.showInputDialog(null,"Enter Name Employee 3: ");

emp3hours = JOptionPane.showInputDialog(null,"Enter Hours Work: ");
hourswork3=Double.parseDouble(emp3hours);

emp3otime = JOptionPane.showInputDialog(null,"Enter Overtime pay: ");
ot3=Double.parseDouble(emp3otime);

emp3rate = JOptionPane.showInputDialog(null,"Enter Rate per hour: ");
rate3=Double.parseDouble(emp3rate);

basicsalary3= (rate3 * hourswork3);
deduction=(sss + ph + pagibig + tax);
grosssalary3= basicsalary3 - deduction;
netsalary3=grosssalary3 + ot3;

JOptionPane.showMessageDialog(null,"Name employee 1: " + emp1name  + "
" 
+ "Number of working hours: " + hourswork1 + "
" 
+ "Overtime pay: " + ot1 + "
" 
+ "Deduction: " + deduction + "
"
+ "Basic Pay: " + basicsalary1 + "
"
+ "Gross Pay: " + grosssalary1 + "
"
+ "Net Pay: " + netsalary1);


JOptionPane.showMessageDialog(null,"Name employee 2: " + emp2name  + "
" 
+ "Number of working hours: " + hourswork2 + "
" 
+ "Overtime pay: " + ot2 + "
" 
+ "Deduction: " + deduction + "
"
+ "Basic Pay: " + basicsalary2 + "
"
+ "Gross Pay: " + grosssalary2 + "
"
+ "Net Pay: " + netsalary2);

JOptionPane.showMessageDialog(null,"Name employee 3: " + emp3name  + "
" 
+ "Number of working hours: " + hourswork3 + "
" 
+ "Overtime pay: " + ot3 + "
" 
+ "Deduction: " + deduction + "
"
+ "Basic Pay: " + basicsalary3 + "
"
+ "Gross Pay: " + grosssalary3 + "
"
+ "Net Pay: " + netsalary3);

	cont =	JOptionPane.showInputDialog(null,"Try Again? (press y or n) ");
	}while (cont.matches("y"));
	JOptionPane.showMessageDialog(null,"Program closing"  );


}
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.