Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Implementing certain methods for a basic employee managing system

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"

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

  • 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:

  1. aumentarSalario(double porcentaje): Increase the current salary based on a provided percentaje.

  2. cambiarPosicion(String nuevaPosicion): Change the job position of the employee to a new job position.

  3. calcularSalarioAnual(): Return anual salary by muliplying the monthly salary by 12

  4. activarEmpleado(): Change the status of an employee to active.

  5. 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 !
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading