Check the Vehicle! 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.
java programming
I did this int car; int motorbikes; int trucks; int randNum=0; randNum=(int)(Math.random() * +1); for(int a = 1; int a =10; a++) { System.out.print(a); } if(randNum = 1 && a=10) System.out.println("Number of Cars "); else if(randNum = 2 && a=10) System.out.println("Number of MotorBikes "); else if(randNum = 3 && a=10) System.out.println("Number of Trucks "); }
What course is this from?
Information Technology i guess
This seems like AI :)
Artificial intelligence?
I'm talking about the question man.So I should tell you to use a counter :)
lol it's very easy but i can't do your job for you :) I'd tell you put some thought into it.It's very basic.I'll try you to do it on paper first :) Take your time :)
i tried it as you can see above
Try again :) But this time on paper first.
I will help you then if you are not able to do :)
okay let me try first
@Sheraz12345
int cars; int motorbikes; Main Class () int trucks; counter=0 randNum=(int)(Math.Random()* 3)+1; for (int a=0;a<10;a++) { if(a=1; a<10) System.out.println("a"+ car); } else if(a = 2; a<9; a++) { System.out.println("a" + Motor Bikes); } else if (a=3; a<8; a++) { System.out.println("a" + Trucks); } System.out.println("Number of cars = +cars"); System.out.println("Number of MotorBikes = +motorbikes"); System.out.println("Number of Trucks = +trucks");
Yup its correct
REALLY?! OMG I FREAKING THINK HARD ON THIS MAN
Lol Way to go
Have u compiled it ?
Why is decreasing the condition a<10 ,9,8...
i didnt try yet
Well we are using that to check the number of vechiles
i'm using jgrasp for the first time how do i put in the class do u know?
jgrasp never heard of that :P
its okay i shall open my netbeans then .
hang on with me for awhile
yeah netbeans is a good choice
damn have to install it on my desktop
Do u have jdk installed in ur pc
nope
i'm downloading the latest netbeans 8.0 which jdk should i download im using windows home
Come on man u are learning java and u have not installed java developing kit
windows vista*
its in my laptop which is connected to vpn
So use ur laptop
i'm using desktop at home and i cant connect to the vpn at home
but in school i do
wow it says incompatible i download 64 bit !
perhaps my com is 32 bit so how !
It is 32 bit !!!!! gosh!!!!!!!!
Can i have two netbeans in my laptop?
One in school vpn the other in my own personal laptop?
i checked already i think its correct despite getting the "error: class, interface, or enum expected int trucks;"
I would like to ask any assumptions made here?
Yea sure
@emmigrace222 how do i put the array here to generate 10 random numbers
Use rand function which can generate numbers within a certain range or you could make your own function.
Join our real-time social learning platform and learn together with your friends!