• Post Reply Bookmark Topic Watch Topic
  • New Topic

Traffic light simulation  RSS feed

 
Kim wee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I having an assignment and im suppose to code on a traffic light simulation. but im stuck on drawing out of the road lanes.

so far i manage to draw out the simulation map.

can give me some advice?

thank you




 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kim wee wrote:I having an assignment and im suppose to code on a traffic light simulation. but im stuck on drawing out of the road lanes.

Seems an odd thing to be worrying about. Have you actually written your traffic light code yet?

To be honest, if it was me, I'd probably write them out in list form for the moment, eg:
Road NS Northbound: {whatever}
Road NS Southbound: {whatever}
Road EW Eastbound: {whatever}
...
That way you can add things like turning lanes later on if you need to.

Mind you, I loathe GUI coding .

Winston
 
Kim wee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i manage to get my code runing abit.

but how do i remove the object in the list i added?


 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kim wee wrote:but how do i remove the object in the list i added?

Well, assuming that 'carArrayH' is a List of some kind, the normal way would be to use remove(Object). However, since you haven't stored your Car object anywhere else, I suspect you'll need some kind of removeCarAt(x, y) method, which makes me wonder if, in fact, a List is what you want (A 2D array may do just as well).

Also:seems a bit redundant. What about simply:(Of course we may just be missing the code that explains why you're doing it that way.)

I fear however that you may be getting too bogged down in the "how" rather than concentrating on the "what" - as in "what does this program need to do". Have you written any pseudo-code? Or indeed a simple description of what the program does?

Trying to code from scratch in Java is a very hard thing to do, and most experienced programmers spend a lot more time sorting out the problem in their head (or on paper) than they ever do coding in Java.

The only other piece of advice I can give you is this: separate the operation of your traffic lights (the problem) from (a) how the output will look (the representation), and (b) the mechanism you use to simulate traffic flow (your test module). This will hopefully help you to look at the application from different viewpoints and work on a specific piece without affecting anything else.

Winston
 
Kim wee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
noted. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!