Anda di halaman 1dari 7

Program to calculate employee salary using abstract classes

by hinata Tue Mar 29, 2011 12:06 pm /*SALARY CALCULATED FOR BOTH EMPLOYEES IN SERVICE AND RETIRED BASED*/ /* ON THE OBJECT THAT CALLS THE salary() METHOD, WHICH IS OVERRIDEN */ /* IN THE Serving AND Retired CLASSES */ /* ---------------------------------------------------------------- */ import java.io.*; abstract class Employee { private int employeeID; private String employeeName; private String department; private boolean inService; Employee() { employeeID = 0; employeeName = ""; department = ""; inService = true; } Employee(int employeeID, String employeeName, String department, boolean inService) { this.employeeID = employeeID; this.employeeName = employeeName; this.department = department; this.inService = inService; } public void salary() { } public void show() { System.out.println("-----------------------------------------------"); System.out.println("| \t\t\tPARAM SOFTWARES |\n|\t\t\t POLLACHI |\n|\n"); System.out.println("|\tSALARY SLIP FOR THE MONTH OF |\n|"); System.out.println("\tEmployeeID : " + employeeID); System.out.println("|\tEmployeeName : " + employeeName); System.out.println("|\tDepartment : " + department); System.out.println("|\tInService : " + (inService ? "Yes" : "No")); } }

final class Serving extends Employee { private float basic; private byte da; private byte hra; private byte trAllowance; private byte cca; private byte cgegis; private byte cghs; private float gross; private float net; Serving() { } Serving(int employeeID, String employeeName, String department, boolean inService, float basic, byte da, byte hra, byte trAllowance,byte cca,byte cgegis,byte cghs) { super(employeeID,employeeName,department,inService); this.basic = basic; this.da = da; this.hra = hra; this.trAllowance = trAllowance; this.cca = cca; this.cgegis = cgegis; this.cghs = cghs; } public void salary() { float deductions; gross = basic + basic * ((float)(da) / 100) + cca; gross += basic * ((float)(hra) / 100) + basic * ((float)(trAllowance) / 100); deductions = cgegis + cghs; net = gross - deductions; } public void showData() { super.show(); System.out.println("|\tBasic Pay : " + basic + "\t| CGEGIS : " + cgegis); System.out.println("|\tDA : " + (basic * (float)(da) / 100) + "\t| CGHS : " + cghs); System.out.println("|\tHRA : " + (basic * ((float)(hra) / 100)) + "\t|"); System.out.println("|\tTraining Allowance : " + (basic * (float)(trAllowance) / 100) + "\t|"); } } final class Retired

{ private float basic; private byte da; private byte ma; private float comm; private float net; Retired() { } Retired(int employeeID, String employeeName, String department, boolean inService, float basic, byte da, byte ma, float comm) { super(employeeID,employeeName,department,inService); this.basic = basic; this.da = da; this.ma = ma; this.comm = comm; } } public class EmployeeSalary { public static void main(String [] args) throws IOException, Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); byte n; int employeeID; String employeeName; String department; boolean inService; float basic, comm; byte da, hra, trAllowance, cca, cgegis, cghs, ma; System.out.print("Enter The Number Of Employees : "); n = Byte.parseByte(br.readLine()); for (byte i = 1;i <= n;i++) { System.out.println("Employee Record : " + i); System.out.print("EmployeeID : "); employeeID = Integer.parseInt(br.readLine()); System.out.print("EmployeeName : "); employeeName = br.readLine(); System.out.print("Department : "); department = br.readLine(); System.out.print("InService (true/false) : "); inService = Boolean.parseBoolean(br.readLine()); if(inService)

{ System.out.print("Basic Pay : "); basic = Float.parseFloat(br.readLine()); } }

#include<stdio.h> void main() { long int bs,da,hra,pf; printf("\nEnter The Basic Salary of Employee: "); scanf("%d",&bs); printf("\nDA : %d",da=bs*30/100); printf("\nHRA : %d",hra=bs*25/100); printf("\nPF : %d",pf=bs*30/100); printf("\nNet Salary: %d",da+hra+pf); } Hey frnds pls tell me is it a ryt answer or wrong? Help me out

Is This Answer Correct ?

29 Yes

13 No

2 Don Re: WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary display all contents? Answer #2

the program does not yield proper result, cos long int is used and then only "%d", instead just use "%ld" like i did in following "#include<stdio.h> void main() { long int bs,da,hra,pf; printf("\nEnter The Basic Salary of Employee: "); scanf("%ld",&bs); printf("\nDA : %ld",da=bs*30/100); printf("\nHRA : %ld",hra=bs*25/100); printf("\nPF : %ld",pf=bs*30/100); printf("\nNet Salary: %ld",da+hra+pf); }

Is This Answer Correct ?

12 Yes

10 No

0 Yarmia Anuj Kalundia

Re: WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary display all contents? Answer #3

wrong

Is This Answer Correct ?

6 Yes

3 No

0 Balachander Re: WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary display all contents? Answer #4

IF UR BASIC SALARY 5000 RS. HRA=B*25/100; HRA=1250; DA=BS*30/100; DA=1500; PF=BS*30/100; PF=1500; NET SALARY=HRA+DA+PF+BS; NET SALARY=1250+1500+1500+5000; NET SALARY= 9250 RS. THIS IS MY CORRECT ANSWER

Is This Answer Correct ?

12 Yes

10 No

0 Sanjay Re: WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary

display all contents? Answer #5

My question is that, my salary is Rs. 12,000/-. In my salary, How can calculate the Basic, DA, HRA and other conveyance allowancs. This is for the PF. Please send the detaisl and examples to me at the earleist. Hope for the same. Thanks Salim Kumar A.P.

Is This Answer Correct ?

8 Yes

6 No

0 Salim Kumar A.p. Re: WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary display all contents? Answer #6

jst add basic into net salary with da n hra n pf