我正在做我的中期项目,我或多或少已经完成了。我遇到的唯一问题是,当我运行程序并要求我输入员工的全名时,编译器会向我抛出有关扫描仪的异常。我从Scanner
输入转到“扫描仪用户输入”,但它仍然无法正确编译。任何有关问题所在的提示将不胜感激。
package midterm;
import java.util.Scanner;
public class Midterm {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
System.out.print("If you wish to enter another's employee's inforamtion"
+ " please press 1, else to exit enter 0.");
int choice = user_input.nextInt();
if (choice == 1) {
System.out.print("What is the employee's full name. ");
String empName = user_input.next();
System.out.printf("Please enter the number of hours that the employee has worked. ");
double hoursWorked = user_input.nextDouble();
System.out.printf("Please enter the employee's hourly pay rate. ");
double payRate = user_input.nextDouble();
displayPay(empName, calculatePay(hoursWorked, payRate));
}
else if (choice == 0) {
System.exit(0);
}
}
public static double calculatePay(double hours, double pay) {
double wages = 0;
if (hours <= 40) {
wages = hours * pay;
}
if (hours > 40) {
double regPay = hours * pay;
double overTime = (hours - 40) * pay * 1.5;
wages = regPay + overTime;
}
return wages;
}
public static void displayPay(String name, double empWage) {
System.out.print("-----------------------------------------");
System.out.print("Employee Name: " + name);
System.out.print("Pay Check Amount: $" + empWage);
System.out.print("-----------------------------------------");
}
}