I am a complete beginner in the programming world. I was asked to create a basis employee managing system by creating a class called Empleado, which should include the following attributes:
-
nombre (String) this means "name"
-
edad (int) this means "age"
-
salario (double) this means "salary"
-
posicion (String) this means "position" as in Job position or Job title, NOT geographical position.
-
añosExperiencia (int) this means years of experience
-
estado (Boolean, active/inactive) this one means "status"
I also need to implement the following methods:
-
aumentarSalario(double porcentaje): Increase the current salary based on a provided percentaje.
-
cambiarPosicion(String nuevaPosicion): Change the job position of the employee to a new job position.
-
calcularSalarioAnual(): Return anual salary by muliplying the monthly salary by 12
-
activarEmpleado(): Change the status of an employee to active.
-
desactivarEmpleado(): Change the status of an employee to inactive.
I think I was able to implement the methods 1. and 3., but I’m having a hard time implementing the other three methods. Also, I’m not really sure if the way I implemented the method calcularSalarioAnual() is correct.
So far, this is what I have:
public class Empleado
{
String nombre;
int edad;
double salario;
String posicion;
int añosExperiencia;
boolean estado;
double salarioAnual;
public Empleado(String name,int edad, double salario, int añosExperiencia, boolean estado)
{
this.nombre = nombre;
this.edad = edad;
this.salario = salario;
this.añosExperiencia = añosExperiencia;
this.estado = estado;
this.posicion = posicion;
}
public void aumentarSalario(double porcentaje) {
salario = salario + (salario*porcentaje)/100;
}
public double getSalarioMensual() {
return salario;
}
public void calcularSalarioAnual(double salarioAnual) {
salarioAnual = 12*salario;
}
public double getSalarioAnual() {
return salarioAnual;
}
public String getPosicion() {
return posicion;
}
}
Any help is greatly appreciated.
I have attempted to search similar methods or examples which can give me an idea of how to construct the methods: cambiarPosicion(String nuevaPosicion), activarEmpleado(), and desactivarEmpleado(), however, I did not find anything useful for my case.
>Solution :
it’s pretty easy, first for the cambiarPosicion, this method will take a String input and will set the "posicion" attribute to the new one :
public void cambiarPosicion(String nuevaPosicion) {
this.posicion = nuevaPosicion;
}
Then to activate / deactivate the employee, you can simply set its state to True or False :
public void activarEmpleado() {
this.estado = true;
}
public void desactivarEmpleado() {
this.estado = false;
}
On a side note,
- The calcularSalarioAnual method does not needs any parameter :
public void calcularSalarioAnual() {
salarioAnual = 12 * salario;
}
- You forgot to add the posicion as an argument in your constructor, so it will always be an empty string !