ライセンス番号(文字列)、時間および料金を含むprivate void display car()に入力されたすべての配列値を出力するにはどうすればいいですか? 次に、guiを使用してSearch car()で配列のライセンス番号(文字列)を検索し、ライセンス番号のコンソールで結果を表示します。時間と手数料。検索が見つからない場合、エラーが表示されます。配列内の文字列を検索してすべての配列を出力するにはどうすればよいですか?
Scanner inputMenuChoice = new Scanner(System.in);
private int getMenuItem()
{
System.out.println("\nPlease select from the following");
System.out.println(ENTER_CAR + ". Enter licence plate and hours stayed");
System.out.println(DISPLAY_CARS + ". Display all licence plates, hours and fees");
System.out.println(DISPLAY_STATISTICS + ". Display Statistics");
System.out.println(SEARCH_CARS + ". Search for car");
System.out.println(EXIT + ". Exit the application");
System.out.print("Enter choice==> ");
return inputMenuChoice.nextInt();
}
private void processCars()
{
int choice = getMenuItem();
while (choice != EXIT)
{
switch (choice)
{
case ENTER_CAR:
enterCar();
break;
case DISPLAY_CARS:
displayAllCars();
break;
case DISPLAY_STATISTICS:
displayStatistics();
break;
case SEARCH_CARS:
searchCar();
break;
default:
System.out.println("ERROR choice not recognised");
}
choice = getMenuItem();
}
}
private void enterCar()
{
String licPlate="",hr="";
int d=1,carMax,numHr;
int i=0;
Scanner sa=new Scanner(System.in);
//for(int i=0;i<a.length;i++)
{
licPlate=JOptionPane.showInputDialog(null, "Please enter the license plate of the car");
while(licPlate.isEmpty())
{
if(licPlate.isEmpty())
{
JOptionPane.showMessageDialog(null, "Error - Licence Plate cannot be blank");
licPlate=JOptionPane.showInputDialog(null, "Please enter the license plate of the car");
}
}
hr=JOptionPane.showInputDialog(null, "Enter the number of hour(s) car was parked (1-12)");
numHr=Integer.parseInt(hr);
while(numHr>12 || numHr<1)
{
if(numHr>12 || numHr<1)
{
JOptionPane.showMessageDialog(null, "Error - Hours must be between 1 and 12", "Error", JOptionPane.ERROR_MESSAGE);
hr=JOptionPane.showInputDialog(null, "Enter the number of hour(s) car was parked (1-12)");
}
}
System.out.printf("Details for car %d entered\n",d);
a[i]=new Car(licPlate,numHr);
d++;
}
{System.out.println(a[i]);}
i++;
}
private void displayAllCars()
{
}
private void displayStatistics()
{
}
private void searchCar()
{
}
public static void main(String [] args)
{
CarPark app = new CarPark();
app.processCars();
}
}
これは、あなたの答えはあなたのコードにこのsegmentyを使用しているのですか?これはコード作成サービスではありません。 – Lee