예제 #1
0
  @Test
  public void testDrive() {
    Car testCar = new Car(50);
    testCar.addGas(20);
    testCar.drive(25);
    double gallons = testCar.getGasInTank();
    assertEquals(19.5, gallons, 1e-6);

    testCar.drive(100);
    gallons = testCar.getGasInTank();
    assertEquals(17.5, gallons, 1e-6);
  }
예제 #2
0
 public void update(double timeInterval) {
   super.resetAvSpeedStats();
   for (Road r : getOutgoingRoads()) {
     if (r != null) {
       r.handleLC(this, false);
     }
   }
   // Tom : Do le normal lane update Cliff: ME GUSTA
   for (Road r : getIncomingRoads()) {
     if (r != null) {
       r.handleLC(this, false);
       for (Lane l : r.getLanes()) {
         if (l.getCars().size() > 0) {
           Car fCar = l.getCars().getFirst();
           if (!fCar.isIsGate()
               && fCar.getPosition() + fCar.getLength() >= (l.getLength() - fCar.getMinSpace())) {
             // The front of the car reaches the end of the road within its minimal spacing
             if (fCar.getPath().isEmpty()) {
               l.deleteCar(fCar);
             } else {
               super.updateFirst(timeInterval, r, l, getNextRoadForCar(fCar), fCar);
             }
           } else {
             fCar.drive(0, 0, true, timeInterval);
           }
           super.updateLane(timeInterval, l, r);
         }
       }
     }
   }
 }
예제 #3
0
 public static void main(String[] args) {
   int way;
   Car myCar = new Car();
   myCar.start();
   way = myCar.drive(5);
   System.out.println(way);
   myCar.stop();
 }
예제 #4
0
  public static void main(String args[]) {
    Driver lewis = new Driver("Lewis Hamilton", 30, "UK");
    System.out.println(
        lewis.getName() + " Age: " + lewis.getAge() + " Country: " + lewis.getCountry());

    Driver vettel = new Driver("Sebastian Vettel", 28);
    vettel.setCountry("Germany");
    vettel.print();

    Car c1 = new Car("F1 W06", "Mercedes", lewis, 500);
    System.out.println(
        c1.getName()
            + " Manufacturer: "
            + c1.getManufacturer()
            + " Driver: "
            + c1.getDriver().getName()
            + " FuelCapacity: "
            + c1.getFuelCapacity());
    c1.refuel(100);
    c1.drive(400);
    System.out.println(
        c1.getName()
            + " Manufacturer: "
            + c1.getManufacturer()
            + " Driver: "
            + c1.getDriver().getName()
            + " FuelCapacity: "
            + c1.getFuelCapacity());

    Car c2 = new Car("SF15-T", "Ferrari");
    c2.setDriver(vettel);
    c2.setFuelCapacity(400);
    c2.print();
    c2.refuel(50);
    c2.drive(500);
    c2.print();

    c1.getDriver().print();
    c2.getDriver().print();

    return;
  }
예제 #5
0
  @Test
  public void test() {
    Car car = new Car(50);

    car.addGas(20); // Tank 20 gallons
    car.drive(100); // Drive 100 miles
    double gasLeft = car.getGasInTank(); // Get gas remaining in tank

    // expected 18
    assertEquals(18, gasLeft, 0);
  }
예제 #6
0
 /** Drive all cars until they have arrived. */
 public void driveCars() {
   while (cars.size() > 0) {
     int i = 0;
     while (i < cars.size()) {
       Car c = cars.get(i);
       c.drive();
       if (c.hasArrived()) {
         cars.remove(i);
       } else {
         i++;
       }
     }
   }
 }
예제 #7
0
 /** Drive all cars until they have arrived. */
 public void driveCars() {
   while (cars.size() > 0) {
     int i = 0;
     while (i < cars.size()) {
       Car c = cars.get(i);
       ArrayList<Person> arrived = c.drive();
       // TODO: Add print statement here
       for (Person passenger : arrived) {
         System.out.println(c.getDriverName() + " drops off " + passenger.getName());
       }
       if (c.hasArrived()) {
         cars.remove(i);
       } else {
         i++;
       }
     }
   }
 }
예제 #8
0
 public static void main(String[] args) {
   Driver driver = new BenzDriver();
   Car car = driver.driverCar();
   car.drive();
 }
예제 #9
0
파일: Car.java 프로젝트: gohv/Learn
  public static void main(String[] args) {

    Car myFastCar = new Car(2007);
    myFastCar.startEngine();
    myFastCar.drive(1628);
  }
예제 #10
0
 public void drive() {
   super.drive();
   accelerate(getRoad().getSpeedLimit(), 0);
 }
예제 #11
0
 public static void main(String[] args) {
   CarFactory factory = new BenzCarFactory();
   Car car = factory.getBussinessCar();
   car.drive();
 }
예제 #12
0
  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);
  }