473,414 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

traffic light

2
Hi everybody

I'm making a project where i need to make a simulation of a traffic light.
The cars appear randomly, and are represented by letter, the traffic light stays open for x seconds, then it closes. The output is something like this.

0: ....-
1: ....-
2: a...-
3: .a..-
4: ..a.-
5: b..a|
6: .b.a|
7: ..ba|
8: ...ba|
9: ....ba|
10: .....b-
11: ......-
...
42: .j.i..h-
43: ..j.i..-
44: k..j.i.-
45: .k..j.i|

Thanks a lot in advance.
Jan 13 '08 #1
8 4396
RedSon
5,000 Expert 4TB
Hi everybody

I'm making a project where i need to make a simulation of a traffic light.
The cars appear randomly, and are represented by letter, the traffic light stays open for x seconds, then it closes. The output is something like this.

0: ....-
1: ....-
2: a...-
3: .a..-
4: ..a.-
5: b..a|
6: .b.a|
7: ..ba|
8: ...ba|
9: ....ba|
10: .....b-
11: ......-
...
42: .j.i..h-
43: ..j.i..-
44: k..j.i.-
45: .k..j.i|

Thanks a lot in advance.
We aren't going to do your homework for you. Did you have a question about this or did you just want to share?
Jan 13 '08 #2
razer
2
I don't want anyone to solve this for me, i just need some help in some parts.

For example this part:

Expand|Select|Wrap|Line Numbers
  1. for (d=0;  d <= m;  d += 1) {  
  2.             System.out.println(d);
By the way, 'd' are the seconds, 'm' the second the program stops, and 'n' the time the traffic light takes to change.
This cicle doens't seem to work, but if i put a number instead of the 'm', it works properly, if 'd' is every second, i want it to stops once it reaches the value of 'm', but i can't get it to do that.
Jan 13 '08 #3
RedSon
5,000 Expert 4TB
I don't want anyone to solve this for me, i just need some help in some parts.

For example this part:

Expand|Select|Wrap|Line Numbers
  1. for (d=0;  d <= m;  d += 1) {  
  2.             System.out.println(d);
By the way, 'd' are the seconds, 'm' the second the program stops, and 'n' the time the traffic light takes to change.
This cicle doens't seem to work, but if i put a number instead of the 'm', it works properly, if 'd' is every second, i want it to stops once it reaches the value of 'm', but i can't get it to do that.
First, as I'm sure you'll quickly learn, having variable names like "seconds' and "stopSecond" will eliminate the need for you to say things like "By the way, 'd' are the seconds, 'm' the second the program stops..." In case you can't read between the lines, use descriptive variable names. The other problem is that I have no idea how to help you because you have not given me all the information about how your loop works, there is some random variable in there and I don't know what it is.
Jan 13 '08 #4
Stubert
20
Have you made sure that 'm' has been initialised? If it is has not then it will either never execute the loop because the program does not know what 'm' is..
Jan 15 '08 #5
RedSon
5,000 Expert 4TB
Have you made sure that 'm' has been initialised? If it is has not then it will either never execute the loop because the program does not know what 'm' is..
Exactly! Which brings us back around to variable names. Please use descriptive variable names.
Jan 15 '08 #6
BigDaddyLH
1,216 Expert 1GB
Exactly! Which brings us back around to variable names. Please use descriptive variable names.
Story time: I was teaching Java and I saw that one student's Java code had the variable names: variable1, variable2, variable3, ... I pointed this out and he still didn't see the problem. I told him that Java is an object-oriented language, so suggestive names shouldn't be hard to think of. Later I checked his code and he had renamed the variables... to object1, object2, object3...
Jan 15 '08 #7
Ganon11
3,652 Expert 2GB
Kids are very dumb at times.

Anyway, I was having a problem with String706 in my program, it's the one right after String705, and I think it leads into String707...
Jan 15 '08 #8
RedSon
5,000 Expert 4TB
Story time: I was teaching Java and I saw that one student's Java code had the variable names: variable1, variable2, variable3, ... I pointed this out and he still didn't see the problem. I told him that Java is an object-oriented language, so suggestive names shouldn't be hard to think of. Later I checked his code and he had renamed the variables... to object1, object2, object3...
I don't understand what the problem here is...?
Jan 15 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bla | last post by:
Hi, There is a new Yahoo group called " Traffic-Cams " This group discusses everything related to online and realtime traffic-cameras We have a very extensive links-section with links to...
2
by: macca | last post by:
Hi, I would like to create a control that looks like a set of traffic lights. This will output alarm states and if the user clicks on the control it will open up a dialog that gives more...
26
by: Wouter van Teijlingen | last post by:
Dear Readers, This is my first post to this group. I was pointed to this group in a other vb group, so i have better luck here! For my learning curve of VB .NET i want to make a traffic...
2
by: matt | last post by:
Does anyone know of a service, that provides driving traffic information in the form of xml? I see several large cities have information on the web, including traffic cameras. traffic.com has an...
4
by: jaja99 | last post by:
hello to all.. PLEASE HELP ME!! i wanted to make a traffic light in vb using if then else.. 3 circles (red, yellow & green) and a timer i don't know how to make them appear one by one.....
9
by: Brigitte Behrmann | last post by:
Hi There This is my first time on the site. I am studing information technology and one of my subjects is HTML & Javascript. I am battling and have an assignment due, please help! I need to use...
2
by: juvilan | last post by:
I need a code for my thesis and I don’t know how to create a VB code for the traffic light.
1
by: davidjacob | last post by:
any program code in vb studio that can help in designing traffic light is appreciated thanks
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.