Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-10-2010, 08:47 AM   PM User | #1
Gage84
New to the CF scene

 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Gage84 is an unknown quantity at this point
Using Java to Create Simulations

Hi,

I am in my 3rd year of doing Computer Science and for my project I am doing a traffic light simulation to see how cars intereact with traffic lights
i.e if it is green the cars will move off, if it is red the cars will stop. I want the simulation to be interactive giving the user control of when to change the lights.

My question is, is it possible to do this on Java? I have been to numerous libraries and on the internet/Youtube and have found no books that specialise in Java with simulations. I always thought Java is an OO language, so cannot work out how a simulation will control objects using logic rules (I maybe wrong)

My second question is, would it be better to do it on another programming language?

all opinions welcomed

Patrick.
Gage84 is offline   Reply With Quote
Old 11-10-2010, 01:34 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Sure, this is doable. I probably wouldn't use Java for a real life traffic control system, but for simulations yeah its good to go.
What you describe sounds like it would fit well with the state change / observation pattern (if you're unfamiliar, a control object simply tracks objects that 'watch' them and notify them of any changes). Actually, I think Java has a built-in Observer and Notifier class, so you may need to poke around for that. If not, they are a cinch to make.
The real tricky part will be setting up all the watches properly. A car could watch a light and react to its changes, but if it doesn't react to other car's changes than you would create a massive pileup since they would all run into each other. It won't be that difficult to add these things in either, but you will need proper planning or you will end up with a disaster in the end.
Then adding multiple lights (which listen to other lights for changes), more cars, lanes, intersections and so forth would be trivial. Intersection feels like it will be a worthwhile class.
What would be neat is to have a driver as well that is rated for carelessness, and will take random chances on red lights O.o. Heh, see how the other drivers react to the carelessness based on their own carelessness level.
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Old 11-12-2010, 12:05 AM   PM User | #3
Gage84
New to the CF scene

 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Gage84 is an unknown quantity at this point
Thanks for that Fou Lu, I will definatley look into it.
Gage84 is offline   Reply With Quote
Old 11-12-2010, 03:27 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You betcha.
Wikipedia up for design patterns observer or notifier. Chances are you'll hit the right one, and the last time I was looking up patterns I remember seeing excellent examples for a huge range of them. These will give you an idea of how to implement if you're not familiar, though I'm not certain if they used a custom class approach or the builtin classes (confirmed, looks like java uses Observer interface and Observable class to short-cut deal with these).
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:31 AM.


Advertisement
Log in to turn off these ads.