please answer my question.
Answers
Answer: The required java progrram is :-
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter employee code number : ");
String eno = scan.next();
System.out.print("Enter basic monthly pay (in decimals) : ");
double pay = scan.nextDouble();
scan.close();
double DA = 0.65*pay;
double HRA = 0.21*pay;
double DF = 0.0333*pay;
double grossSalary = pay+DA+HRA;
double netSalary = grossSalary-DF;
System.out.println("DA of the employee is : "+DA);
System.out.println("HRA of the employee is : "+HRA);
System.out.println("DF of the employee is : "+DF);
System.out.println("Gross Salary of the employee is : "+grossSalary);
System.out.println("Net salary of the employee is : "+netSalary);
}
}
Please mark it as Brainliest.
Code:
import java.util.Scanner;
public class Employee {
float basicPay, grossPay, netPay,
DA, HRA, DF;
String name, codeNo;
void accept( ) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter \n Name - ");
name = sc.nextLine( );
System.out.print(" Code no. - ");
codeNo = sc.next( );
System.out.print(" Basic Pay - ");
basicPay = sc.nextFloat( );
}
void calculate( ) {
DA = 0.65f * basicPay;
HRA = 0.21f * basicPay;
DF = 0.833f * basicPay;
grossPay = basicPay + DA + HRA;
netPay = grossPay - DF;
}
void display( ) {
System.out.println("\nName - " + name);
System.out.println("Code No. - " + codeNo);
System.out.printf("DA - %.2f\n" +
"HRA - %.2f\n" +
"DF - %.2f\n", DA, HRA, DF);
System.out.println("Gross Pay - ₹ " + grossPay);
System.out.println("Net Pay - ₹ " + netPay);
}
public static void main(String[ ] args) {
Employee employee = new Employee( );
employee.accept( );
employee.calculate( );
employee.display( );
}
}
Sample I/O:
Enter
Name - James
Code no. - 12221
Basic Pay - 20000
Name - James
Code No. - 12221
DA - 13000.00
HRA - 4200.00
DF - 16660.00
Gross Pay - ₹ 37200.0
Net Pay - ₹ 20540.0