Last active
May 23, 2016 05:08
-
-
Save yamika/84475cbe867e088347545d0f474f6813 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FuelConsumptionCalculation{ | |
private double fuelConsumptionOldRegulation = 0; | |
private double fuelConsumptionNewRegulation = 0; | |
private SimpleCar[] cars; | |
FuelConsumptionCalculation() { | |
this.fuelConsumptionOldRegulation = 0; | |
this.fuelConsumptionNewRegulation = 0; | |
} | |
FuelConsumptionCalculation(SimpleCar[] cars) { | |
this.cars = cars; | |
} | |
private void calculateFuelConsumption() { | |
for(int i=0;i<cars.length;i++){ | |
System.out.println(cars[i].maker + " OldRegulations is "+ getFuelConsumptionOldRegulations(cars[i].fuel,cars[i].airfuel)); | |
System.out.println(cars[i].maker + " NewRegulations is "+ getFuelConsumptionNewRegulations(cars[i].fuel,cars[i].airfuel)); | |
} | |
} | |
double getFuelConsumptionOldRegulations(double fuel,double airfuel) { | |
return 200/fuel + 11/airfuel; | |
} | |
double getFuelConsumptionNewRegulations(double fuel,double airfuel){ | |
return (double)200/fuel + (double)8/airfuel; | |
} | |
public static void main(String[] args){ | |
SimpleCar[] cars = new SimpleCar[4]; | |
cars[0] = new DeluxeCar("Honda",14,10.5,8); | |
cars[1] = new AdvancedCar("Toyota",15.5,9.5); | |
cars[2] = new SimpleCar("Nissan",13); | |
cars[3] = new DeluxeCar("Van(Nissan)",10.5,6,8); | |
FuelConsumptionCalculation Reports = new FuelConsumptionCalculation(cars); | |
Reports.calculateFuelConsumption(); | |
} | |
} | |
class SimpleCar{ | |
String maker; | |
double fuel; | |
double airfuel = 0; | |
public SimpleCar(String maker,double fuel){ | |
this.maker = maker; | |
this.fuel = fuel; | |
} | |
} | |
class AdvancedCar extends SimpleCar{ | |
double airfuel; | |
public AdvancedCar(String maker,double fuel,double airfuel){ | |
super(maker,fuel); | |
this.airfuel = airfuel; | |
} | |
} | |
class DeluxeCar extends AdvancedCar{ | |
double turnoff; | |
public DeluxeCar(String maker,double fuel,double airfuel,double turnoff){ | |
super(maker,fuel,airfuel); | |
this.turnoff = turnoff; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment