Length of service Increment Dearness Allowance
Up to 10 years 20% of basic 10% of basic
Above 10 and up to 20 years 25% of basic 15% of basic
Above 20 years 30% of basic 20% of basic
Write a program to find new basic by using the following class specifications:
Class : Increment
Data members/Instance variables:
String name : name of the employee
double basic : basic pay of the employee
int pds : length of service of the employee
Member methods :
void getdata(String n, int p, : to accept name, length of service, basic
double bs, double d) and DA
void calculate( ) : to find increment and update basic salary.
void display ( ) : to display length of service and update basic salary in
the format given below:
import java.util.*;
public class Increment
{
static String name = "";
static double basic;
static int pds;
static double DA;
public static void main(String args[])
{
String n = ""; int p; double bs; double d = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Name: ");
n = sc.nextLine();
System.out.print("Enter the basic pay: ");
bs = sc.nextDouble();
System.out.print("Enter the length of service: ");
p = sc.nextInt();
if(p<= 10)
{
d = (bs * 10) / 100;
}
else if(p > 10 && p <= 20)
{
d = (bs * 15) / 100;
}
else if(p > 20)
{
d = (bs * 20) / 100;
}
getdata(n, p, bs, d);
}
static void getdata(String n, int p, double bs, double d)
{
name = n;
pds = p;
basic = bs;
DA = d;
calculate();
}
static void calculate()
{
double inc = 0;;
if(pds<= 10)
{
inc = (basic * 20) / 100;
}
else if(pds > 10 && pds <= 20)
{
inc = (basic * 25) / 100;
}
else if(pds > 20)
{
inc = (basic * 30) / 100;
}
//basic = basic + inc;
display();
}
static void display()
{
System.out.println("Name \t Length of service \t Basic salary \t\t DA");
System.out.println(name + " \t " + pds + " \t \t " + basic + " \t\t " + DA);
}
}
No comments:
Post a Comment