public static void main(String[] args) {

    Vehicle v1 = new Vehicle(new Battery(100));
    if (v1.start()) {
      System.out.println("v1 start");
    }

    v1 = new Vehicle(new Battery(0));
    if (!v1.start()) {
      System.out.println("v1 stop");
    }
  }
Exemple #2
0
 // gasがない場合startできない
 @Test
 public void startTestZeroGas() {
   Vehicle v1 = new Vehicle(0, 10);
   assertFalse(v1.start());
 }
Exemple #3
0
 // 両方ある場合startできる
 @Test
 public void startTest() {
   Vehicle v1 = new Vehicle(10, 10);
   assertTrue(v1.start());
 }
Exemple #4
0
 // batteryがない場合startできない
 @Test
 public void startTestzeroBattery() {
   Vehicle v1 = new Vehicle(10, 0);
   assertFalse(v1.start());
 }
  private void handleCars() {
    Logan jimmy = new Logan(30, "SAAVVVZZ877887");
    jimmy.shiftGear(Car.FIRST);
    jimmy.start();
    jimmy.drive(10);
    jimmy.shiftGear(Car.FIFTH);
    jimmy.drive(200);
    jimmy.drive(20.1);
    jimmy.drive(0.2);

    jimmy.stop();

    Car car = new Logan(27, "oiqe0934hkkadsn");

    car.start();

    car.shiftGear(1); // shifts to first gear

    car.drive(0.01); // drives 0.01 KMs

    car.shiftGear(2);

    car.drive(0.02);

    car.shiftGear(3);

    car.drive(0.5);

    car.shiftGear(4);

    car.drive(0.5);

    car.shiftGear(4);

    car.drive(0.5);

    car.shiftGear(5);

    car.drive(10);

    car.shiftGear(4);

    car.drive(0.5);

    car.shiftGear(3);

    car.drive(0.1);

    car.stop();

    float availableFuel = car.getAvailableFuel();

    float fuelConsumedPer100Km = car.getAverageFuelConsumption();

    float pollutionPerKm = car.getPollution();

    System.out.println("Available fuel: " + availableFuel);
    System.out.println("Average session fuel consumption: " + fuelConsumedPer100Km);
    System.out.println("Pollution: " + pollutionPerKm);

    Vehicle vehicle = new Golf(30, "1987ddkshik289"); // available fuel and chassis number

    vehicle.start();

    vehicle.drive(1);

    vehicle.stop();

    Car car1 = (Car) vehicle;

    float availableFuel1 = car1.getAvailableFuel();

    float fuelConsumedPer100Km1 = car1.getAverageFuelConsumption();

    float pollutionPerKm1 = car1.getPollution();

    System.out.println("Available fuel: " + availableFuel1);
    System.out.println("Average session fuel consumption: " + fuelConsumedPer100Km1);
    System.out.println("Pollution: " + pollutionPerKm1);
  }