29 lines
670 B
Java
29 lines
670 B
Java
package org.util;
|
|
|
|
import org.*;
|
|
import org.model.ElectricCar;
|
|
import org.model.GasCar;
|
|
import org.model.SportsCar;
|
|
import org.model.Vehicle;
|
|
|
|
/*
|
|
* Utility class to inspect vehicles.
|
|
* Demonstrates instanceof and polymorphism.
|
|
*/
|
|
|
|
public class VehicleInspector {
|
|
|
|
public static void inspect(Vehicle v)
|
|
{
|
|
v.basicInfo();
|
|
|
|
switch (v)
|
|
{
|
|
case ElectricCar electricCar -> System.out.println("Check battery system");
|
|
case SportsCar sportsCar -> System.out.println("Check brakes and performance");
|
|
case GasCar gasCar -> System.out.println("Check engine and oil");
|
|
default -> {}
|
|
}
|
|
}
|
|
}
|