我是Java的初学者,并试图创建一个非常基本的汽车租赁计划。我遇到的问题是,当我第一次运行我的代码时,它按预期工作。每当我在完成汽车预订后提供用户输入为Y时,为了继续下一个客户,代码将停止,并且#34;输入您的姓名",扫描仪无法从键盘读取字符。请提供最佳解决方案来解决此问题。
import java.util.Scanner;
public class Application {
static Scanner input = new Scanner(System.in);
static CustomerActivities customer = new CustomerActivities();
static CarInventory carInventory = new CarInventory();
public static void main(String[] args) {
userName();
customer.displayWelcomeMessage();
carInventory.carList();
carInventory.displayCars();
carOptions();
carInventory.searchCarAvailability();
carConfirmation();
carInventory.rentCar();
carInventory.getInventory();
anotherCustomer();
input.close();
}
public static void userName(){
System.out.println("Enter your name");
System.out.println("boom");
String userName = input.nextLine();
System.out.println("bane");
customer.setUserName(userName);
}
public static void carOptions(){
System.out.println("Enter the car you would like to Rent");
int userCarOption = input.nextInt();
carInventory.setUserCarOption(userCarOption);
}
public static void carConfirmation(){
char userConfirmation = input.next().charAt(0);
carInventory.setUserConfirmation(userConfirmation);
}
public static void anotherCustomer(){
System.out.println("Do you have any other customer");
char customerContinue = input.next().charAt(0);
if(customerContinue =='Y'){
System.out.println("You can start entering the next customer details");
userName();
}
}
}