# Vehicle
Date: 2020-11-15

de.hems.trafficsim

## Class Vehicle

- java.lang.Object
- - de.hems.trafficsim.Vehicle

    public class Vehicle
    extends java.lang.Object

Model class which represents a vehicle in the simulation.

### Field Summary

Fields
`protected float` `brakeProb` probability of the vehicle to brake without reason
`protected float` `curVelocity` current velocity of the vehicle
`protected int` `id` a number to index the vehicle
`protected float` `maxVelocity` maximum velocity of the vehicle
`protected float` `position` current position of the vehicle on the track
`protected float` `trackLength` length of the track the vehicle is placed on

### Constructor Summary

Constructors
Constructor and Description
`Vehicle(int id, int position, float maxVelocity, float brakeProb, float trackLength)` Constructs a new vehicle.

### Method Summary

All Methods Instance Methods Concrete Methods
`float` `getCurVelocity()` Getter for curVelocity
`float` `getMaxVelocity()` Getter for maxVelocity
`float` `getPosition()` Getter for position
`void` `setBrakeProb(float brakeProb)` Setter for brakeProb
`void` `setMaxVelocity(float maxVelocity)` Setter for maxVelocity
`void` `timeElapse()` Updates the position of the vehicle according to it's previously calculated speed.
`void` `updateVelocity(float distanceForerunner)` Calculates the new velocity of the vehicle based on the following rules: Increase by one if the vehicle is slower than it's maximum speed Random brake by one Break if the distance to the forerunner is less than it's speed

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### id

    protected int id

a number to index the vehicle

#### position

    protected float position

current position of the vehicle on the track

#### curVelocity

    protected float curVelocity

current velocity of the vehicle

#### maxVelocity

    protected float maxVelocity

maximum velocity of the vehicle

#### brakeProb

    protected float brakeProb

probability of the vehicle to brake without reason

#### trackLength

    protected float trackLength

length of the track the vehicle is placed on

### Constructor Detail

#### Vehicle

    public Vehicle(int id,
                   int position,
                   float maxVelocity,
                   float brakeProb,
                   float trackLength)

Constructs a new vehicle.

Parameters:
  `id` - a number to index the vehicle
  `position` - current position of the vehicle on the track
  `maxVelocity` - maximum velocity of the vehicle
  `brakeProb` - probability of the vehicle to brake without reason
  `trackLength` - length of the track the vehicle is placed on

### Method Detail

#### getPosition

    public float getPosition()

Getter for position

Returns:
  position

#### getCurVelocity

    public float getCurVelocity()

Getter for curVelocity

Returns:
  curVelocity

#### getMaxVelocity

    public float getMaxVelocity()

Getter for maxVelocity

Returns:
  maxVelocity

#### setBrakeProb

    public void setBrakeProb(float brakeProb)

Setter for brakeProb

#### setMaxVelocity

    public void setMaxVelocity(float maxVelocity)

Setter for maxVelocity

#### updateVelocity

    public void updateVelocity(float distanceForerunner)

Calculates the new velocity of the vehicle based on the following rules:

1. Increase by one if the vehicle is slower than it's maximum speed
2. Random brake by one
3. Break if the distance to the forerunner is less than it's speed

Parameters:
  `distanceForerunner` - distance to the forerunner of the vehicle

#### timeElapse

    public void timeElapse()

Updates the position of the vehicle according to it's previously calculated speed.