String parts = input.nextLine(); という行にまだ問題があります。クラッシュし続け、「行」を削除しても問題ありませんが、スペースを含む文字列全体を読み取って保存したいです。以前にすべての変数と配列を宣言したと仮定します。
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;
}
}