package class9_3_VehicleFunctions_start; public abstract class Vehicle { public static final int DEFAULT_NORTH_METERS_PER_SEC = 4; /** The car's position */ private double northMeters = 0; /** The car's speed */ private double northMetersPerSec; /** Create a car at the specied position with the specified initial velocity * * @param northMeters position north of game center of vehicle's center of mass * @param northMetersPerSec velocity north of game center of vehicle's * center of mass, in m/s. */ public Vehicle(double northMeters, double northMetersPerSec) { this.northMeters = northMeters; this.northMetersPerSec = northMetersPerSec; } /** * Create a car at the specified position. * The vehicle will be moving north by default at about 10mph * @param northMeters position north of game center of vehicle's center of mass */ public Vehicle(double northMeters) { this(northMeters, DEFAULT_NORTH_METERS_PER_SEC); } public double getNorthMeters() { return northMeters; } public double getNorthMetersPerSec() { return northMetersPerSec; } /** * Step forward the simulation by one second. */ public void step() { northMeters += northMetersPerSec; } @Override public abstract String toString(); @Override public boolean equals(Object object) { if(!(object instanceof Vehicle)) { return false; } Vehicle other = (Vehicle)object; return this.northMeters == other.northMeters && this.northMetersPerSec == other.northMetersPerSec; } @Override public int hashCode() { return Double.hashCode(northMeters) + Double.hashCode(northMetersPerSec); } }