accessing individual objects' coordinate data
in
Programming Questions
•
17 days ago
I'm learning OOP and I made a program
with a multiple instances of a 'vehicle' object. All the vehicles were created in this way:
for (int i = 0; i < 5; i++) {
vehicles.add(new Vehicle(new PVector(random(width), random(height)), random(2, 5), random(0.1, 0.5)));
Vehicle veh_loc = vehicles.get(i);
}
I can get the group of vehicles' coordinate data (using vehicles.get(i) ) but I want to be able to access the location data (loc.x, loc.y) for specifically the 3rd vehicle in the 'vehicles' group. Is there a way to tag/index each one of the vehicles that are created so that I can reference specific vehicles within that group?
1