Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that Fou Lu, I will definatley look into it.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •