5
The line marked with /*ISSO AQUI*/
is being ignored, ie the name for the second employee is not read, only the last name.
import java.util.Scanner;
public class EmployeeTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Employee Empregado1 = new Employee();
Employee Empregado2 = new Employee();
System.out.print("Enter your name: ");
String nome = input.nextLine();
Empregado1.setName(nome);
System.out.print("Enter your last name: ");
String sobreNome = input.nextLine();
Empregado1.setLastName(sobreNome);
System.out.print("Enter you salary: ");
double salario = input.nextDouble();
Empregado1.setSalary(salario);
double novoSalario = Empregado1.getSalary() + (0.10*Empregado1.getSalary());
Empregado1.setSalary(novoSalario);
Empregado1.showEmployee();
//-----------------------------------------------------------------------------
System.out.print("\n\nEnter your name: ");
/*ISSO AQUI*/ nome = input.nextLine(); /*ISSO AQUI*/
Empregado2.setName(nome);
System.out.print("Enter your last name: ");
sobreNome = input.nextLine();
Empregado2.setLastName(sobreNome);
System.out.print("Enter you salary: ");
salario = input.nextDouble();
Empregado2.setSalary(salario);
novoSalario = Empregado2.getSalary() + (0.10*Empregado2.getSalary());
Empregado2.setSalary(novoSalario);
Empregado2.showEmployee();
input.close();
}
}
In fact what nextdouble does not read is the line break left by enter, and as nextLine consumes the string until there is a line break, it ends up consuming the line break left by nextdouble.
– user28595
Thanks for the correction.
– Gabriel Cândido