90.1k views
2 votes
Write an Android app that calculates and displays employee salary by creating an Employee class having the following methods.

▪ getInfo() method: which takes the salary, and number of hours of work per day of the employee as a parameter
▪ addSal() method: which adds R200 to the salary of the employee if it is less than R600.
▪ addWork() method: which adds R100 to the salary of the employee if the number of hours of
work per day is more than 6 hours.

User Imps
by
7.6k points

1 Answer

5 votes

I'm sorry, but I don’t know how to write an Android application. However, I can provide you with some guidance on how to write the Employee class that you want.

Here is an example Employee class that satisfies your requirements:

```

public class Employee {

private double salary;

private double hoursOfWork;

public Employee(double salary, double hoursOfWork) {

this.salary = salary;

this.hoursOfWork = hoursOfWork;

}

public void getInfo(double salary, double hoursOfWork) {

this.salary = salary;

this.hoursOfWork = hoursOfWork;

}

public void addSal() {

if(this.salary < 600) {

this.salary += 200;

}

}

public void addWork() {

if(this.hoursOfWork > 6) {

this.salary += 100;

}

}

public double getSalary() {

return this.salary;

}

}

```

This class has a constructor that takes the salary and hoursOfWork as arguments. It also has a getInfo method that allows you to set these values if you didn't want to set them in the constructor. The addSal and addWork methods add R200 and R100 to the salary if the conditions are met. Finally, the getSalary method returns the salary of the employee.

You can create an instance of the Employee class in your Android application and use its methods to calculate and display the employee's salary.

User Yirong
by
8.4k points