このプログラムでは、プリセット値を持つ CarOrder クラスから 2 つのオブジェクトを作成しています。次に、さらに 2 つのオブジェクトを作成するために、さらに 2 セットの値をユーザーに要求しています。残念ながら、最初の税ステータスを入力した後、ユーザーが 2 番目のバイヤーの値を入力するのをスキップします。この 1 つの質問をランダムにスキップするのはなぜですか?
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
CarOrder speedy = new CarOrder("Speedy Rental", "Mini Cooper", 22150, 15, true);
CarOrder zip = new CarOrder("Zip Car Co.", "Ford Fusion", 27495, 6, true);
System.out.println("Enter Buyer: ");
String buyer1 = keyboard.nextLine();
System.out.println("Enter the type of car being purchased: ");
String car1 = keyboard.nextLine();
System.out.println("Enter the cost of this purchase: ");
double cost1 = keyboard.nextDouble();
System.out.println("Enter quantity of cars being purchased: ");
int quantity1 = keyboard.nextInt();
System.out.println("Enter tax status: ");
boolean tax1 = keyboard.nextBoolean();
System.out.println("Enter Buyer: ");
String buyer2 = keyboard.nextLine();
System.out.println("Enter the type of car being purchased: ");
String car2 = keyboard.nextLine();
System.out.println("Enter the cost of this purchase: ");
int cost2 = keyboard.nextInt();
System.out.println("Enter quantity of cars being purchased: ");
int quantity2 = keyboard.nextInt();
System.out.println("Enter tax status: ");
boolean tax2 = keyboard.nextBoolean();
CarOrder state = new CarOrder(buyer1, car1, cost1, quantity1, tax1);
CarOrder it = new CarOrder(buyer1, car2, cost2, quantity2, tax2);
System.out.println("Chicago Car Wholesalers" );
System.out.println("Oct. 30th, 2012");
System.out.println("New Car Order Report");
}
}