public static void testarEmpregado() {
Scanner sc = new Scanner(System.in);
System.out.print("Digite o nome: ");
String nome = sc.nextLine();
System.out.println("Digite o endereço: ");
String endereco = sc.nextLine();
System.out.println("Digite o número de telefone:");
String telefone = sc.nextLine();
System.out.println("Digite o código do setor");
int codigoSetor = sc.nextInt();
sc.nextLine();
System.out.println("Digite o salário base");
float salarioBase = sc.nextFloat();
sc.nextLine();
System.out.println("Digite o valor do imposto");
float imposto = sc.nextFloat();
sc.nextLine();
Empregado emp = new Empregado(nome, endereco, telefone, codigoSetor, salarioBase, imposto);
float sal = emp.calcularSalario();
System.out.printf("Salário do empregado: %.2fn", sal);
sc.close();
}
E quando chega na hora de escanear o nome o java lança a java.util.NoSuchElementException
Testei seu código e não ocorre nenhum erro. Basta informar os dados no formato esperado.
Poderia explicar melhor o momento que ocorre o erro?
Envie também a StackTrace.