我仍然对 String parts = input.nextLine(); 这一行有疑问。它不断崩溃,如果我删除“Line”,那很好,但我想读取包括空格在内的整个字符串并存储它。假设我之前已经声明了所有变量和数组。
System.out.print("Enter registration number of vehicle: ");
String inputREGO = input.nextLine();
System.out.print(inputREGO);
boolean flag = false;
for(int i=0; i<6; i++){
if(inputREGO.equalsIgnoreCase(services[i].getregoNUMBER())){
System.out.print("Enter Part Description: ");
String parts = input.next();
System.out.print("Enter Part Cost: ");
Double cost = input.nextDouble();
services[i].addPARTDETAILS(parts, cost);
flag = true;
}
}
if(!flag)
System.out.println("No registration number were found in the system.");
public boolean addPARTDETAILS(String partDESCRIPTION, double partCOST){
if(partDESCRIPTION.isEmpty() || partCOST <= 0){
System.out.println("Invalid input, please try again!");
return false;
}
else{
StringBuffer strBuf = new StringBuffer();
strBuf.append(" ").append(partDESCRIPTION).append(" ($").append(partCOST).append(")");
partLIST += strBuf;
System.out.printf("\n%10s", partLIST);
System.out.println("\n Parts recorded successfully for vehicle " + getregoNUMBER());
totalPART+=partCOST;
return true;
}
}