Calculate annual salary

-1

• Model an employee. It must have the employee's name ( String ), the department where he works ( String ), his salary ( double ), the date of entry into the bank ( String ) and his RG ( String ) .

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

My draft (I'm trying to call the function calculates for the yearly gain, but I can not even do 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);
    }
}
    
asked by anonymous 08.08.2017 / 23:20

1 answer

3

It's close. In fact you need to reread the statement, it says even the names of the methods that should be created.

There is not much because the method is static there. It has syntax errors. Also has field that does not seem to be needed.

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

It has other problems that for a basic exercise does not matter, but in real code this is not how it is coded.

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());
    }
}

See running on ideone . And no Coding Ground . Also I placed in GitHub for future reference .

    
08.08.2017 / 23:28