-2
配列はカウンタで宣言されています。オブジェクトがアレイに追加されるたびにカウンタを使用する必要があります。Javaで新しい配列オブジェクトを作成するにはどうすればよいですか?
// declare Parcel array and parcel count variable
private static Parcel[] parcels = new Parcel[10];
private static int parcelCount = 0;
スキャナ内の情報が新しいパーセルオブジェクトを作成し、アレイパーセル内の次に使用可能な(空の)場所に格納する必要があります。
私は何を持っていますか?それは動作していないようです。私は間違って何をしていますか?
System.out.print("Enter Parcel Number: ");
String parcelNumber = sc.nextLine();
String [] parcels = new String[0];
parcelCount ++;
System.out.print("Enter Sender Name: ");
String senderName = sc.nextLine();
String [] parcels = new String[1];
parcelCount ++;
System.out.print("Enter Return Address: ");
String returnAddress = sc.nextLine();
String [] parcels = new String[2];
parcelCount ++;
System.out.print("Enter Recipient Name: ");
String recipientName = sc.nextLine();
String [] parcels = new String[3];
parcelCount ++;
System.out.print("Enter Delivery Address: ");
String deliveryAddress = sc.nextLine();
String [] parcels = new String[4];
parcelCount ++;
あなたは、配列がどのように機能するかについてのチュートリアルを読んで考えがあります/tutorial/java/nutsandbolts/arrays.html –
...新しいオブジェクトを作成するコードを見せているうちに、その方法を教えてほしいですか? – Stultuske
なぜ '小包 'を作り直しているのですか?あなたはちょうど最後にそれを作成してみませんか?小包数にはどのように名前と住所が関係していますか? – Thomas