I have the following exercise:
Continuing with the previous exercise, now it is necessary to implement the salary to be paid to each teacher, so the corresponding attribute and a method that allows adding the value for said attribute must be added. Following in consideration that: if you have more than 10 years of experience, you will be assigned 3,000, from 5 to 10 years, 2,500, and less than 5 years, 2,000. Update the methods so that the teacher's salary is shown along with his other data.
Class Profesor{
var $nombre;
var $direccion;
var $experiencia;
var $asignatura;
var $anhos;
public function __construct($nombre, $direccion, $experiencia, $asignatura, $anhos){
$this->nombre = $nombre;
$this->direccion = $direccion;
$this->experiencia = $experiencia;
$this->asignatura = $asignatura;
$this->anhos = $anhos;
}
public function get_nombre(){
return $this->nombre;
}
public function set_nombre($x){
$this->nombre = $x;
}
public function get_direccion(){
return $this->direccion;
}
public function set_direccion($x){
$this->direccion = $x;
}
public function get_experiencia(){
return $this->experiencia;
}
public function set_experiencia($x){
$this->experiencia = $x;
}
public function get_asignatura(){
return $this->asignatura;
}
public function set_asignatura($x){
$this->asignatura = $x;
}
public function get_anhos(){
return $this->anhos;
}
public function set_anhos($x){
$this->anhos = $x;
}
function salario(){
if($anhos < 5){
$salario = 2000;
}else if($anhos > 5 && $anhos <= 10){
$salario = 2500;
}else{
$salario = 3000;
}
return $salario;
}
}
Well, in the previous exercise I have created a class with certain attributes. According to this exercise I must add a new attribute (To which I have added anhos) to know how much his salary is. But what leaves me puzzled is the final part "Update the methods so that the teacher's salary is shown along with his other data". Does this mean that I have to create a function to render "salary" as a new attribute without declaring it in the constructor? And if so, how could I do that?
Excuse me but I'm a little green with this OOP thing
Thank you
There are several things to correct:
private
to encapsulate.var
it is very old and in modern versions of PHP it already raises a warning, so avoid using itsalario
in the class$this
in salary calculationget_alldata
that satisfies the requirement "Update the methods so that the teacher's salary is displayed along with their other data"2000
The class would look like this: