Java输入条件

Java输入条件,java,input,dialog,conditional-statements,equals,Java,Input,Dialog,Conditional Statements,Equals,我有两节课。我正在努力使: -客户的电话号码不是空的,为10个字符 否则重新输入 -车辆数量在1到10辆之间(包括1到10辆) 否则重新输入 -燃油箱的数量只能是(2、4、8、10、15、20) 否则重新输入 我不知道如何使电话号码=10位数。在车辆上多次输入(1-10)以外的值后,它会跳到燃油箱的数量。输入(2、4、8、10、15、20)以外的值后相同。我做错了什么?谢谢你的帮助。谢谢 Java代码段 public static void main(String[] args) { Strin

我有两节课。我正在努力使:

-客户的电话号码不是空的,为10个字符
否则重新输入

-车辆数量在1到10辆之间(包括1到10辆)
否则重新输入

-燃油箱的数量只能是(2、4、8、10、15、20)
否则重新输入

我不知道如何使电话号码=10位数。在车辆上多次输入(1-10)以外的值后,它会跳到燃油箱的数量。输入(2、4、8、10、15、20)以外的值后相同。我做错了什么?谢谢你的帮助。谢谢

Java代码段

public static void main(String[] args) {
String firstname = JOptionPane.showInputDialog("Enter your first name");
while (firstname.equals("")){
firstname = JOptionPane.showInputDialog("Enter your first name");
}

String lastname = JOptionPane.showInputDialog("Enter your last name");
while (lastname.equals("")){
lastname = JOptionPane.showInputDialog("Enter your last name");
}

String phone = JOptionPane.showInputDialog("Enter your phone");
while (phone.equals("")){
phone = JOptionPane.showInputDialog("Enter your phone");
}

int nbrVehicles = Integer.parseInt(JOptionPane.showInputDialog("Enter number of vehicles"));
if (nbrVehicles < 1 || nbrVehicles > 10){
JOptionPane.showInputDialog("Enter number of vehicles");
}   

int nbrTanks = Integer.parseInt(JOptionPane.showInputDialog("Enter number of tanks"));
if (nbrTanks != 2 || nbrTanks != 4 || nbrTanks != 8 || nbrTanks != 10 || nbrTanks != 15 || nbrTanks != 200){
JOptionPane.showInputDialog("Enter number of tanks");
} 

VehicleFactory vehicleObject = new VehicleFactory();
vehicleObject.HayloFactory(firstname, lastname, phone, nbrVehicles, nbrTanks);
vehicleObject.calcFuelTankCost();
vehicleObject.calcManufacturingCost();
vehicleObject.calcSubtotal();
vehicleObject.calcTax();
vehicleObject.calcTotal();
vehicleObject.getSummary();             
}
}
publicstaticvoidmain(字符串[]args){
String firstname=JOptionPane.showInputDialog(“输入您的名字”);
while(firstname.equals(“”){
firstname=JOptionPane.showInputDialog(“输入您的名字”);
}
String lastname=JOptionPane.showInputDialog(“输入您的姓氏”);
while(lastname.equals(“”){
lastname=JOptionPane.showInputDialog(“输入您的姓氏”);
}
String phone=JOptionPane.showInputDialog(“输入您的电话”);
while(phone.equals(“”){
phone=JOptionPane.showInputDialog(“输入您的手机”);
}
int nbrvices=Integer.parseInt(JOptionPane.showInputDialog(“输入车辆数量”);
如果(NBR车辆<1 | | NBR车辆>10){
JOptionPane.showInputDialog(“输入车辆数量”);
}   
int nbrTanks=Integer.parseInt(JOptionPane.showInputDialog(“输入坦克数量”);
如果(油箱数!=2个油箱数!=4个油箱数!=8个油箱数!=10个油箱数!=15个油箱数!=200){
JOptionPane.showInputDialog(“输入储罐数量”);
} 
VehicleFactory vehicleObject=新VehicleFactory();
vehicleObject.HayloFactory(名字、姓氏、电话、NBR车辆、NBR坦克);
calcFuelTankCost();
vehicleObject.calcManufacturingCost();
calcSubtotal();
calcTax();
vehicleObject.calcTotal();
vehicleObject.getSummary();
}
}

您可以在以下时间尝试

int nbrVehicles = Integer.parseInt(JOptionPane.showInputDialog("Enter number of vehicles"));
while (nbrVehicles < 1 || nbrVehicles > 10)
    nbrVehicles = Integer.parseInt(JOptionPane.showInputDialog("Enter number of vehicles"));
}   
int nbrvices=Integer.parseInt(JOptionPane.showInputDialog(“输入车辆数量”);
而(NBR车辆<1 | | NBR车辆>10)
nbrvices=Integer.parseInt(JOptionPane.showInputDialog(“输入车辆数量”));
}