Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

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.

OpenStudy (anonymous):

java programming

OpenStudy (anonymous):

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 "); }

OpenStudy (hba):

What course is this from?

OpenStudy (anonymous):

Information Technology i guess

OpenStudy (hba):

This seems like AI :)

OpenStudy (hba):

Artificial intelligence?

OpenStudy (hba):

I'm talking about the question man.So I should tell you to use a counter :)

OpenStudy (hba):

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 :)

OpenStudy (anonymous):

i tried it as you can see above

OpenStudy (hba):

Try again :) But this time on paper first.

OpenStudy (hba):

I will help you then if you are not able to do :)

OpenStudy (anonymous):

okay let me try first

OpenStudy (anonymous):

@Sheraz12345

OpenStudy (anonymous):

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");

OpenStudy (sheraz12345):

Yup its correct

OpenStudy (anonymous):

REALLY?! OMG I FREAKING THINK HARD ON THIS MAN

OpenStudy (sheraz12345):

Lol Way to go

OpenStudy (sheraz12345):

Have u compiled it ?

OpenStudy (anonymous):

Why is decreasing the condition a<10 ,9,8...

OpenStudy (anonymous):

i didnt try yet

OpenStudy (sheraz12345):

Well we are using that to check the number of vechiles

OpenStudy (anonymous):

i'm using jgrasp for the first time how do i put in the class do u know?

OpenStudy (sheraz12345):

jgrasp never heard of that :P

OpenStudy (anonymous):

its okay i shall open my netbeans then .

OpenStudy (anonymous):

hang on with me for awhile

OpenStudy (sheraz12345):

yeah netbeans is a good choice

OpenStudy (anonymous):

damn have to install it on my desktop

OpenStudy (sheraz12345):

Do u have jdk installed in ur pc

OpenStudy (anonymous):

nope

OpenStudy (anonymous):

i'm downloading the latest netbeans 8.0 which jdk should i download im using windows home

OpenStudy (sheraz12345):

Come on man u are learning java and u have not installed java developing kit

OpenStudy (anonymous):

windows vista*

OpenStudy (anonymous):

its in my laptop which is connected to vpn

OpenStudy (sheraz12345):

So use ur laptop

OpenStudy (anonymous):

i'm using desktop at home and i cant connect to the vpn at home

OpenStudy (anonymous):

but in school i do

OpenStudy (anonymous):

wow it says incompatible i download 64 bit !

OpenStudy (anonymous):

perhaps my com is 32 bit so how !

OpenStudy (anonymous):

It is 32 bit !!!!! gosh!!!!!!!!

OpenStudy (anonymous):

Can i have two netbeans in my laptop?

OpenStudy (anonymous):

One in school vpn the other in my own personal laptop?

OpenStudy (sheraz12345):

http://www.compileonline.com/compile_java_online.php

OpenStudy (anonymous):

i checked already i think its correct despite getting the "error: class, interface, or enum expected int trucks;"

OpenStudy (anonymous):

I would like to ask any assumptions made here?

OpenStudy (sheraz12345):

Yea sure

OpenStudy (anonymous):

@emmigrace222 how do i put the array here to generate 10 random numbers

OpenStudy (hba):

Use rand function which can generate numbers within a certain range or you could make your own function.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!