Skip to content
Snippets Groups Projects
CarSpecifics.java 1.14 KiB
Newer Older
  • Learn to ignore specific revisions
  • SAHIN Melis damla's avatar
    TP
    SAHIN Melis damla committed
    package agency;
    
    import util.TimeProvider;
    
    public class CarSpecifics implements VehiclesSpecifics {
        private int numberOfSeats;
        private int productionYear;
        private static final int PRICE_PER_SEAT_FOR_OLD_CAR = 20;
        private static final int PRICE_PER_SEAT_FOR_NEW_CAR = 40;
    
        public CarSpecifics(int numberOfSeats, int productionYear) {
            if (numberOfSeats < 1) {
                throw new IllegalArgumentException("Invalid number of seats: " + numberOfSeats);
            }
            this.numberOfSeats = numberOfSeats;
            this.productionYear = productionYear;
        }
    
        public int getNumberOfSeats() {
            return numberOfSeats;
        }
    
        public int getProductionYear() {
            return productionYear;
        }
    
        boolean isNew() {
            int currentYear = TimeProvider.currentYearValue();
            return (currentYear - productionYear) <= 5;
        }
    
        @Override
        public double calculateDailyRentalPrice() {
            return numberOfSeats * (isNew() ? PRICE_PER_SEAT_FOR_NEW_CAR : PRICE_PER_SEAT_FOR_OLD_CAR);
        }
    
        @Override
        public String getDetails() {
            return (numberOfSeats > 1 ? numberOfSeats + " seats" : "1 seat");
        }
    }