java – Create class inheritance

Question:

I'm studying object-oriented Java programming and I need to do the following exercise:

Implement the class Funcionario and the Class Gerente .

  1. Create the Assistente class, which is also an Funcionario , and which has a registration number (do the GET method). Override the exibeDados() method.
  2. Knowing that Technical Assistants have a salary bonus and that Administrative Assistants have a shift (day or night) and an additional night, create the Tecnico and Administrativo classes.

I created the following code:

public class Funcionario {
    String nome;
    String cpf;
    double salario;
    int matricula;

    public void exibeDados(){
        System.out.println("Nome: " + nome  + " Cpf: " + cpf + " Salário: " + salario + " Matricula: " + matricula);
    }   
}


    public class Gerente extends Funcionario {
        String departamento;
    }

    public class Assistente extends Funcionario{

        public void getMatricula(int matricula){
            this.matricula = matricula;
        }

        public void exibeDados(){
            System.out.println("Nome: " + nome  + " Cpf: " + cpf + " Salário: " + salario + " Matricula: " + this.matricula);
        }
    }


public class Administrativo extends Assistente {
    String turno;

    public void adicionalNoturno(double adicional){
        if(turno == "noturno" || turno == "Noturno"){
            this.salario = this.salario+adicional;
        }
    }
}

public class Tecnico extends Assistente {

    public double bonusSalarial(){
        this.salario = this.salario+(this.salario*0.1);
        return this.salario;
    }

}

Is there any error in the construction of methods and inheritances or any error in general taking into account the statement of the exercise.?

Answer:

The statement doesn't give much detail, so I have to consider that a lot of things are right, even if I wouldn't do it in real code, and the code does things that the statement doesn't ask for. It is also true that the statement is weird.

I find it strange that a class has a field and only its descendant has a get method to get this field, but I can't say this is wrong according to the weak requirements.

Other than that I don't see problems for a simple exercise (I won't comment on money being manipulated with a double because that doesn't matter in an exercise).

Scroll to Top