Compare commits

...

3 Commits

Author SHA1 Message Date
Waetschker Daniel (uib17511)
58054d6eea change datatype of timestep from int to float 2020-10-29 13:54:39 +01:00
Waetschker Daniel (uib17511)
b2bc60394a Merge remote-tracking branch 'origin/master'
# Conflicts:
#	app/src/main/java/de/hems/trafficsim/MainActivity.java
#	app/src/main/java/de/hems/trafficsim/Track.java
2020-10-29 13:46:59 +01:00
Waetschker Daniel (uib17511)
a3dd3b6585 implement and integrate VehicleTimeRecord 2020-10-29 13:37:08 +01:00
2 changed files with 11 additions and 4 deletions

View File

@ -1,11 +1,13 @@
package de.hems.trafficsim;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Observable;
public class Track extends Observable {
protected List<Vehicle> vehicles;
protected List<List<VehicleTimeRecord>> vtr_list;
protected float trackLength;
public List<Vehicle> getVehicles() {
@ -19,7 +21,7 @@ public class Track extends Observable {
public Track(int numberVehicles, float trackLength) {
this.trackLength = trackLength;
this.vehicles = createVehiclesList(numberVehicles);
this.vtr_list = new LinkedList<>();
}
protected List<Vehicle> createVehiclesList(int numberVehicles){
@ -46,9 +48,12 @@ public class Track extends Observable {
}
v.updateVelocity(distanceForerunner);
}
List <VehicleTimeRecord> records = new ArrayList<>(vehicles.size());
this.vtr_list.add(records);
for(Vehicle v: vehicles){
v.timeElapse(50);
VehicleTimeRecord vtr = new VehicleTimeRecord(v.id, v.position, v.curVelocity, timeStep);
records.add(vtr);
}
this.setChanged();

View File

@ -13,12 +13,14 @@ public class VehicleTimeRecord {
return timestep;
}
protected int id;
protected float position;
protected float velocity;
protected float timestep;
public VehicleTimeRecord(float position, float velocity, float timestep) {
this.position = position;
public VehicleTimeRecord(int id, float position, float velocity, float timestep) {
this.id = id;
this.position = position; //needed???
this.velocity = velocity;
this.timestep = timestep;
}