Auto.java
/** Represents an automobile. */ public class Auto extends Vehicle { private String licensePlate; public Auto(String vin, String plate) { super(vin); licensePlate = plate; } // TODO: Override the equals method of the Object class to // test that VIN and license plate number are identical. public boolean equals(Object otherObject) { Auto other = (Auto) otherObject; return licensePlate.equals(other.licensePlate); } }
Vehicle.java
/** Represents a vehicle of any type. */ public class Vehicle { private String id; public Vehicle(String anId) { id = anId; } public boolean equals(Object otherObject) { Vehicle other = (Vehicle) otherObject; return id.equals(other.id); } }
AutoTester.java
public class AutoTester { public static void main(String[] args) { Vehicle auto1 = new Auto("1234567890", "A141G3"); Vehicle auto2 = new Auto("1234567890", "5ZSN090"); Vehicle auto3 = new Auto("14916253649", "A141G3"); Vehicle auto4 = new Auto("1234567890", "A141G3"); System.out.println(auto1.equals(auto1)); System.out.println("Expected: true"); System.out.println(auto1.equals(auto2)); System.out.println("Expected: false"); System.out.println(auto1.equals(auto3)); System.out.println("Expected: false"); System.out.println(auto1.equals(auto4)); System.out.println("Expected: true"); } }