String licensePlate = “”; // e.g. “New York 543 A23”
double speed = 0.0; // in kilometers per hour
double maxSpeed = 120.0; // in kilometers per hour
void floorIt( )
{
this.speed = this.maxSpeed;
}
void accelerate(double deltaV)
{
this.speed = this.speed + deltaV;
if (this.speed > this.maxSpeed) {
this.speed = this.maxSpeed;
}
if (this.speed < 0.0) {
this.speed = 0.0;
}
}
}
class CarTest4 {
public static void main(String[] args) {
Car c = new Car();
c.licensePlate = “New York A45 636”;
c.maxSpeed = 123.45;
System.out.println(c.licensePlate + “ is moving at “ + c.speed +
“ kilometers per hour.”);
for (int i = 0; i < 15; i++) {
c.accelerate(10.0);
System.out.println(c.licensePlate + “ is moving at “ + c.speed +
“ kilometers per hour.”);
}
}
}