In: Computer Science
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again
EmployeeTest:
$emp1=new Employee("john","doe",20);
$emp2=new Employee("kate","kron",40);
echo "Employee salaries before rise\n";
echo "Employee 1: \n". (12 * $emp1->getSalary());
echo "\nEmployee 2: \n". (12 * $emp2->getSalary()."\n");
echo "Employee salaries after rise\n";
$emp1->setSalary(24);
$emp2->setSalary(48);
echo "Employee 1: \n". (12 * $emp1->getSalary());
echo "\nEmployee 2: \n". (12 * $emp2->getSalary());
Employee class:
class Employee{
var $firstName;
var $lastName;
var $salary;
public function __construct($firstName,$lastName,$salary){
$this->firstName=$firstName;
$this->lastName=$lastName;
$this->salary=$salary;
}
public function getFirstName(){
return $this->firstName;
}
public function setFirstName($firstName){
$this->firstName=$firstName;
}
public function getlastName(){
return $this->lastName;
}
public function setlastName($lastName){
$this->lastName=$lastName;
}
public function getSalary(){
return $this->salary;
}
public function setSalary($salary){
if($salary>0){
$this->salary=$salary;
}
else{
$this->salary=0;
}
}
}
Expected output: