o1.carsim

package o1.carsim

Type members

Classlikes

class Car(val fuelConsumption: Double, val tankSize: Double, initialFuel: Double, initialLocation: Pos)

The class Car represents virtual cars which can drive about on a surface. A car has a fuel tank that contains gasoline, which is spent as the car moves but can be added using an appropriate method.

The class Car represents virtual cars which can drive about on a surface. A car has a fuel tank that contains gasoline, which is spent as the car moves but can be added using an appropriate method.

Although some aspects of a car object are immutable (e.g., fuel consumption rate), some others change (e.g., location, fuel).

Value parameters:
fuelConsumption

the fuel consumption of the new car in liters per 100 km

initialFuel

the initial amount of fuel in the car’s tank, in liters (at most equal to tank size)

initialLocation

the starting location of the car

tankSize

the size of the new car’s fuel tank, in liters

Value members

Concrete methods

def carTest(): Unit

A small program that uses the class Car. Students are free to extend and customize it.

A small program that uses the class Car. Students are free to extend and customize it.