Skip to content
Snippets Groups Projects
AbstractVehicle.java 1.36 KiB
Newer Older
  • Learn to ignore specific revisions
  • SAHIN Melis damla's avatar
    TP
    SAHIN Melis damla committed
    package agency;
    
    import util.TimeProvider;
    
    public abstract class AbstractVehicle implements Vehicle {
        protected String brand;
        protected String model;
        protected int productionYear;
    
        protected static final int MINIMAL_YEAR_VALUE = 1900;
    
        public AbstractVehicle(String brand, String model, int productionYear) {
            int currentYear = TimeProvider.currentYearValue();
            if (productionYear < MINIMAL_YEAR_VALUE || productionYear > currentYear) {
                throw new IllegalArgumentException("Invalid production year: " + productionYear);
            }
            this.brand = brand;
            this.model = model;
            this.productionYear = productionYear;
        }
    
        @Override
        public String getBrand() {
            return brand;
        }
    
        @Override
        public String getModel() {
            return model;
        }
    
        @Override
        public int getProductionYear() {
            return productionYear;
        }
    
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
    
            AbstractVehicle that = (AbstractVehicle) o;
    
            return productionYear == that.productionYear &&
                    brand.equals(that.brand) &&
                    model.equals(that.model);
        }
    
        @Override
        public abstract String toString();
    
        @Override
        public abstract double dailyRentalPrice();
    }