Skip to content
Snippets Groups Projects
Select Git revision
  • d01f6fffd3d5f21bad5bef44effcd0f3aabee209
  • main default protected
  • master
3 results

AbstractVehicle.java

  • Forked from LABOUREL Arnaud / formula Template
    7 commits behind, 3 commits ahead of the upstream repository.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AbstractVehicle.java 1.73 KiB
    package agency;
    
    import util.TimeProvider;
    
    public abstract class AbstractVehicle implements Vehicle {
      private static final int MINIMAL_YEAR_VALUE = 1900;
      private final String brand;
      private final String model;
      private final int productionYear;
    
      @Override
      public int hashCode() {
        int result = brand.hashCode();
        result = 31 * result + model.hashCode();
        result = 31 * result + productionYear;
        return result;
      }
    
      @Override
      public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || this.getClass() != o.getClass()) return false;
    
        AbstractVehicle that = (AbstractVehicle) o;
    
        if (productionYear != that.productionYear) return false;
        if (!brand.equals(that.brand)) return false;
        return model.equals(that.model);
      }
    
      AbstractVehicle(String brand, String model, int productionYear) {
        int currentYearValue =  TimeProvider.currentYearValue();
        if(productionYear < MINIMAL_YEAR_VALUE || productionYear > currentYearValue)
          throw new IllegalArgumentException(productionYear + " is not a correct year (comprised between "
                  + MINIMAL_YEAR_VALUE + " and " + currentYearValue + ")");
        this.productionYear = productionYear;
        this.brand = brand;
        this.model = model;
      }
    
      @Override
      public String getBrand() {
        return brand;
      }
    
      @Override
      public String getModel() {
        return model;
      }
    
      @Override
      public int getProductionYear() {
        return productionYear;
      }
    
      public abstract String kindOfVehicle();
      public abstract String vehicleDetails();
    
      @Override
      public String toString() {
        return kindOfVehicle() + " " + brand + " " + model + " " + productionYear + " (" + vehicleDetails() + ")" + " : "
                + dailyRentalPrice() + "€";
      }
    }