Create class inheritance

3

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

Implement class Funcionario and class Gerente .

  • Create the class Assistente , which is also a Funcionario , and which has a number of (% method). Override the GET method.
  • Knowing that Technical Assistants have a salary bonus and that the Administrative Assistants have one shift (day or night) and one additional create the exibeDados() and Tecnico 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;
        }
    
    }
    

    There is some error in the construction of methods and inheritance or some error in general taking into account the statement of the exercise.?

        
    asked by anonymous 20.03.2016 / 16:49

    1 answer

    3

    The statement does not give many details, so I have to consider that a lot of things are right, even though I would not do it in real code. The code does things that the statement does not ask for. It's also true that the statement is weird.

    I find it strange that a class has an attribute and only its descendant has a get method to get this attribute. But I can not say that this is wrong according to the weak requirements.

    Otherwise I see no problems for a simple exercise (I will not comment on money being manipulated with double because this is not the case in an exercise).

        
    20.03.2016 / 17:07