Assume that vehicles are going through a two-way traffic intersection. There are three types of vehicles: car, motor bikes and trucks. Generate a series of 10 random integers, between 1 and 3, inclusive. The numbers represent the type of vehicle as stated below:

Number Vehicle Category

1 Car

2 Motor bikes

3 Trucks

Write a program, using a for loop, to count how many vehicles going through the traffic intersection are cars, motor bikes and trucks. Then, the program should print out the numbers for each vehicle category. There is no user input for this program. How do i do it so they will add up the sum of each vehicle? Thank you.

The answer should be something like

Number of cars = X

Number of motor bikes = Y

Number of Trucks = Z

but i'm getting

Total number of vehicle:

cars

motorbikes

motorbikes

cars

Trucks

Trucks

motorbikes

motorbikes

Trucks

cars

public static void main(String[] args) {

int countCar = 0;

int countBike = 0;

int countTruck = 0;

int all=0;

Scanner sc = new Scanner (System.in);

System.out.println("Total number of vehicle:");

for (int series = 1; series<=10; series++) {

all = (int) (Math.random()*3)+1;

if (all==1)

{

System.out.println(" cars " );

}

else if (all==2)

{

System.out.println(" motorbikes " );

}

else if (all==3)

{

System.out.println(" Trucks " );

}

}

}

}