0
I am having difficulties in some methods (when you will have to return or when you are void ,parameters or not etc). Why the last two methods of Employee is returning null?
package employee;
public class Employee {
private String firstName,lastName;
private Double salarioMensal,anual,aumentoAnual;
public Employee(String nome,String sobrenome,double salario){
firstName = nome;
lastName = sobrenome;
salarioMensal = salario;
}
public void setFirstName(String nome){
firstName = nome;
}
public void setlastName(String sobrenome){
lastName = sobrenome;
}
public void setSalarioMensal(double salario){
salarioMensal = salario;
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public Double getSalarioMensal(){
return salarioMensal;
}
public void boasVindas(){
System.out.printf("\n Seja bem vindo Sr(a) %s %s \n",getFirstName(),getLastName());
}
public void setAnual(double salario){
salarioMensal = salario;
anual = salarioMensal*12;
}
public void setAmentoAnual(double anualtotal){
anualtotal = anual;
aumentoAnual = anualtotal*0.10;
}
public Double getAnual(){
return anual;
}
public Double getAumentoAnual(){
return aumentoAnual;
}
public void displayFinish1(){
System.out.printf("\n Sr(a). %s .\nO seu salário acumulado em 12 meses será:%.2f.\n",getFirstName(),getAnual());
System.out.printf("Após 12 meses terá um aumento de 10 por cento,ficando:\n %.2f \n.",getAumentoAnual());
}
}
/***O TESTE****/
package employee;
import java.util.Scanner;
public class EmployeeTest {
public static void main(String [] args){
String nome,nome2 , sobrenome,sobrenome2;
Double salario ,salario2;
Scanner entrada = new Scanner(System.in);
System.out.printf("\n Entre com o primeiro nome\n");
nome = entrada.nextLine();
System.out.printf("Entre com o Sobrenome\n");
sobrenome = entrada.nextLine();
System.out.printf("Entre com o salário mensal\n");
salario = entrada.nextDouble();
Employee employee1 = new Employee(nome,sobrenome,salario);
employee1.boasVindas();
employee1.displayFinish1();
}
}
It would be because you never defined the variable
aumentoAnual
? If you do not set a value, it is always null because it is a typeDouble
.– user28595