• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to keep timers for several objetcs at the same time  RSS feed

 
David Martínez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there!

I'm making a Parking Lot System, and I need timers to execute the leaveLot method.

First, I generate a car in a empty slot, the slots saves the current time and the leaving time (beetwen 1 and 15 minutes after current time).

Since I'm having max 8 cars, I need to keep track each random leaving time generated.

Once the leaving time is met, the car should disappear.

How could I do this ?

Example

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37469
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fun! It sounds like you need an array or ArrayList. It also sounds like you need a Car class.
 
David Martínez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Fun! It sounds like you need an array or ArrayList. It also sounds like you need a Car class.


I'm actually writing a mess of a code

I'm only using one ArrayList name OccupiedSlot, which, when the systems starts, the method reads the csv file (where I save all the cars info). The method returns the slot's number that is currently empty and can be occupied.

Btw, could you suggest me a good book about object modeling? I know I have to have a car class, but I don't, I'm fairly new to coding and I'm trying to get better.


cars.csv

SlotOccupied,Agency,Model,ID,CurrentTime, Leaving Time


 
Norm Radder
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the object to display movements in "realtime" or to process events in their order of occurrence?
An approach for the later: instead of using timers, use a priority queue containing events in time-to-execute order.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!