我应该提示输入雇员的姓名,工资和工作时间。它对员工1的工作正常,但是当涉及到员工2时,即使代码相同,它也会跳过询问姓名的问题。
import java.util.Scanner;
public class Employees {
public static void main(String args[]) {
Scanner inputScanner = new Scanner (System.in);
String e1;
String e2;
String e3;
double pay1;
double pay2;
double pay3;
int hours1;
int hours2;
int hours3;
double paycheck1;
double paycheck2;
double paycheck3;
double tax = .053;
double takeHome = .947;
System.out.println("What is the first employee's name?");
e1 = inputScanner.nextLine();
System.out.println("How much do you make?");
pay1 = inputScanner.nextDouble();
System.out.println("How many hours did you work?");
hours1 = inputScanner.nextInt();
paycheck1 = pay1 * hours1;
System.out.println("What is the second employee's name?");
e2 = inputScanner.nextLine();
System.out.println("How much do you make?");
pay2 = inputScanner.nextDouble();
System.out.println("How many hours did you work?");
hours2 = inputScanner.nextInt();
paycheck2 = pay2 * hours2;
System.out.println("What is the third employee's name?");
e3 = inputScanner.nextLine();
System.out.println("How much do you make?");
pay3 = inputScanner.nextDouble();
System.out.println("How many hours did you work?");
hours3 = inputScanner.nextInt();
paycheck3 = pay3 * hours3;
System.out.println(e1 + " will make " + paycheck1 + " before taxes.");
System.out.println(e1 +" will be taxed" + paycheck1 * tax + " dollars.");
System.out.println(e1 +" will take home" + paycheck1 * takeHome + " dollars.");
System.out.println(e2 + " will make " + paycheck2 + " before taxes.");
System.out.println(e2 +" will be taxed" + paycheck2 * tax + " dollars.");
System.out.println(e2 +" will take home" + paycheck2 * takeHome + " dollars.");
System.out.println(e3 + " will make " + paycheck3 + " before taxes.");
System.out.println(e3 +" will be taxed" + paycheck3 * tax + " dollars.");
System.out.println(e3 +" will take home" + paycheck3 * takeHome + " dollars.");
System.out.println("The company will withhold a total of " + (paycheck3 + paycheck2 + paycheck1) * tax + " dollars.");
}
}
一旦我运行它,我就到达了它要第二个雇员的地步,并且它输出了
“第二名雇员的名字是什么? 你赚多少钱? “
完全跳过,让我输入名称。