Создайте класс Employee со следующими закрытыми переменными-членами.
int employeeId
String employeeName
double salary
double netSalary
Включите соответствующий метод get и setters в класс Employee.Напишите следующий метод в классе Employee:
public void calculateNetSalary(int pfpercentage) // This method should take PF percentage as argument. Deduct the PF amount from the salary and set the netSalary.
Создайте класс Main, у которого есть метод main, который вызывает метод для получения входных данных и печатает детали, как показано в примере.
Также напишите метод:
public static Employee getEmployeeDetails() // which gets the employee details and returns the employee object.
public static int getPFPercentage() // which gets the PF percentage and returns the same
Я написал этот код.Вывод правильный, но показывает какую-то ошибку, как ее исправить?
public class Employee {
private int employeeId;
private String employeeName;
private double salary;
private double netSalary;
public static Employee instances= new Employee();
public int getEmployeeId() {
return employeeId;
}
public String getEmployeeName() {
return employeeName;
}
public double getSalary() {
return salary;
}
public double getNetSalary() {
return netSalary;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public void setSalary(double salary) {
this.salary = salary;
}
public void setNetSalary(double netSalary) {
this.netSalary = netSalary;
}
public void calculateNetSalary(int pfpercentage) {
instances.netSalary=(instances.salary)*(1-(((double)pfpercentage)/100));
}
public static Employee getEmployeeDetails(int id, String name,double salary) {
instances.setEmployeeId(id);
instances.setEmployeeName(name);
instances.setSalary(salary);
return instances;
}
public static int getPFPercentage(int pfpercentage)
{ instances.calculateNetSalary(pfpercentage);
' return pfpercentage; '
}
}'
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter id");
int id=sc.nextInt();
System.out.println("Enter name");
sc.nextLine();
String name=sc.nextLine();
System.out.println("Enter salary");
double salary=sc.nextDouble();
Employee e1= Employee.getEmployeeDetails( id, name, salary );
System.out.println("Enter pfpercentage");
Employee.getPFPercentage(sc.nextInt());
System.out.println("Id :"+e1.getEmployeeId());
System.out.println("name :"+e1.getEmployeeName());
System.out.println("salary :"+e1.getSalary());
System.out.println("Net salary :"+e1.getNetSalary());
}
}
FAIL-1:
check the availaibility of getEmployeeDetails() in main method or check wether the signature(returntype/argument/acessspecifier/methodname)of the of the method getEmployeeDetails is correct.
check the availaibility of getPFPercentage() in main method or check wether the signature(returntype/argument/acessspecifier/methodname)of the of the method getPFPercentage() is correct
FAIL-1: check the logic of calculateNetSalary
FAIL-2: check the method of getPFPercentage
FAIL-2: check the method of getEmployeeDetails