Create class inheritance

Asked

Viewed 1,193 times

4

I am studying object-oriented Java programming and need to perform the following exercise:

Implement the class Funcionario and the class Gerente.

  1. Create the class Assistente, which is also a Funcionario, and which has a number of registration (do the method GET). Overwrite the method exibeDados().
  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 classes Tecnico and Administrativo.

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 some error in the construction of methods and inheritances or some error in general taking into account the statement of the exercise.?

1 answer

4


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

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

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

  • Money I must manipulate with float?

  • 1

    No: http://answall.com/a/40048/101. And I strongly advise not to keep creating new accounts, will hinder your learning having a lot of things spread.

  • I read the answer on the other topic, I didn’t know about the Money class, I’ll study more about it. I just didn’t understand what you meant by creating new accounts, it would be creating classes and classes in Java?

  • No, there are already several users who are yours here on the site, the ideal is that only had one. It would be nice to see them all and ask for a moderator to join in one account.

  • But it was the first time I created an account here on the site. I had never created an account here. Could I have duplicated the account or given an error? It has to track the email so I see the name of other users with the same email?

  • You are not Aline?

  • No, my real name is Ewerton.

  • I’m sorry then, she uses some accounts with variations of Gon and asks questions of the same theme and the same way you, passed the impression, forget that part :)

  • Oh yes! I even scared, I thought someone might be using my email. I am researching about the Java Money class. Thank you so much for all the help, I’m starting studies and I’m finding it a little complicated now at the beginning.

  • I didn’t say you should use it, only that the double is not appropriate. Many people think Money an exaggeration. See also: http://answall.com/q/118407/101 and http://answall.com/a/77747/101

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.