Advertisement
CR7CR7

CarEstimate

May 16th, 2022
405
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.time.LocalDate;
  2.  
  3. public class CarPriceEstimator {
  4.    
  5.     public double getSalePrice(String makeAndModel, int yearManufactured, double milesDriven,
  6.             int airBagsCount, boolean hasAbs, boolean hasEbd,
  7.             boolean hasRearViewCamera, boolean hasSunRoof, boolean hasAutoAC,
  8.             boolean hasAccidentHistory) {
  9.        
  10.         double salePrice = getPrice(makeAndModel, yearManufactured);
  11.         int currentYear = LocalDate.now().getYear();       
  12.         int ageOfCar = currentYear - yearManufactured + 1;
  13.         System.out.println("ageOfCar: " +  ageOfCar);
  14.        
  15.            
  16.         // 1. Compute based on yearly depreciation value:
  17.         //       if age of car is less than or equal to 10 then
  18.         //               price depreciates by 5% of original sale price every year
  19.         //               e.g., if original price is 10000, then for 3 year old car
  20.         //                     price depreciated would be 1500, i.e., sale price would be 8500
  21.         //       else
  22.         //               return salePrice * 0.1 (i.e., 10% of current salePrice)
  23.         // Note: Use compound arithmetic assignment operators
  24.        
  25.        
  26.         System.out.println("salePrice after depreciation: " + salePrice);
  27.        
  28.        
  29.         // 2. Security Features
  30.         //      if car does NOT have atleast two airbags AND abs AND ebd
  31.         //              then reduce price by $1000
  32.        
  33.        
  34.         System.out.println("salePrice after accounting for security features: " + salePrice);
  35.        
  36.         // 3. Comfort Features
  37.         // if car has rear-view camera AND either sunroof OR auto AC then
  38.         //    increment price by $500
  39.    
  40.        
  41.         System.out.println("salePrice after accounting for comfort features: " + salePrice);
  42.        
  43.         // 4. Past accidents
  44.         // if car was involved in an accident then
  45.         //     reduce price by $500
  46.        
  47.        
  48.         System.out.println("salePrice after accounting for past accidents: " + salePrice);
  49.        
  50.         // 5. Based on additional miles driven
  51.         double expectedMilesDriven = ageOfCar * 10000.0;
  52.         double additionalMiles = milesDriven - expectedMilesDriven;
  53.        
  54.         // a) if # miles over-driven is greater than 1000 AND less than or equal to 10000 then
  55.         //        reduce sale price by 500
  56.        
  57.        
  58.        
  59.         // b) if # miles over-driven is greater than 10000 AND less than or equal to 30000 then
  60.         //        reduce sale price by 1000
  61.        
  62.        
  63.        
  64.         // c) if # miles over-driven is greater than 30000 then
  65.         //        reduce sale price by 1500
  66.        
  67.        
  68.         System.out.println("salePrice after accounting for miles driven: " + salePrice);
  69.        
  70.         return salePrice;
  71.     }
  72.    
  73.     private double getPrice(String makeAndModel, int yearManufactured) {
  74.         if (makeAndModel.equalsIgnoreCase("ford ecosport")) {
  75.             return 20000.0;
  76.         } else if (makeAndModel.equalsIgnoreCase("honda city")) {
  77.             return 25000.0;
  78.         } else if (makeAndModel.equalsIgnoreCase("toyota camry hybrid")) {
  79.             return 30000.0;
  80.         }
  81.         return 20000.0;
  82.     }
  83.  
  84.     public static void main(String[] args) {
  85.         CarPriceEstimator carPriceEstimator = new CarPriceEstimator();
  86.         double salesPrice = carPriceEstimator.getSalePrice("ford ecosport", 2018, 60000.0, 2, true, false, true, false, false, true);      
  87.     }
  88. }
  89.  
Advertisement
RAW Paste Data Copied
Advertisement