Calculate annual salary

Asked

Viewed 1,275 times

-1

• Model an employee. He must have the employee’s name (String), the department where he works (String), your salary (double), the date of entry into the bank (String) and your ID (String).

• Create a method recebeAumento(double percentual) which increases the employee’s salary according to the parameter passed as argument. Also create a method calculaGanhoAnual, which does not receive any parameter, returning the value of the annual salary considering 13th and holidays.

My draft (I’m trying to call the function calculates for annual gain, but I can’t even get that).

package funcionario;

public class Funcionario {
    String nome, dep, banco, RG;
    double sal, novosal;

    void recebe(double aumento){
        double recebeAumento = this.sal + aumento;
        this.sal = recebeAumento;
    }
    public static double calcula(){
         sal * 12;
    }
    public static void main(String[] args) {
        Funcionario f1;
        f1 = new Funcionario();
        f1.nome = "João";
        f1.dep = "Defesa";        
        f1.banco = "Banco do Brasil S.A";
        f1.RG = "798956-5";
        f1.sal = 27000.0;
        f1.recebe(2000);

        System.out.println("Nome: " + f1.nome + "\nDepartamento: " + f1.dep + "\nBanco: " + f1.banco + "\nRG: " + f1.RG + "\nSalário: " + f1.sal);
    }
}

1 answer

3


It is close. In fact it needs to reread the statement, it even says the names of the methods that should be created.

There is not much because the method is static there. There are syntax errors. There is also a field that does not seem to be necessary.

The statement is not good, I interpreted the calculation as I wanted.

There are other problems that for a basic exercise doesn’t matter, but in real code that’s not how you code.

class Funcionario {
    String nome, dep, banco, RG;
    double salario;

    void recebeAumento(double percentual) {
        salario += salario / 100 * percentual;
    }
    public double calculaGanhoAnual() {
         return salario * 13 + salario / 3;
    }
    public static void main(String[] args) {
        Funcionario f1 = new Funcionario();
        f1.nome = "João";
        f1.dep = "Defesa";        
        f1.banco = "Banco do Brasil S.A";
        f1.RG = "798956-5";
        f1.salario = 27000.0;
        f1.recebeAumento(2000);
        System.out.println("Nome: " + f1.nome + "\nDepartamento: " + f1.dep + "\nBanco: " + f1.banco + "\nRG: " + f1.RG + "\nSalário Anual: " + f1.calculaGanhoAnual());
    }
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

Browser other questions tagged

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