Created
February 4, 2018 07:13
-
-
Save annibuliful/eeb683d591fd47faacaf8c7493e498c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class Car { | |
| public double efficiency; | |
| public double carGas; | |
| public double numberOfDistancePerLitter; | |
| Car(double efficiency){ | |
| this.efficiency = efficiency; | |
| } | |
| public void addGas(double gas){ | |
| this.carGas = gas; | |
| this.numberOfDistancePerLitter = this.carGas * this.efficiency; | |
| } | |
| public double getGasInTank(){ | |
| double carGas = this.numberOfDistancePerLitter / this.efficiency; | |
| return carGas; | |
| } | |
| public void drive(double distance){ | |
| this.numberOfDistancePerLitter -= distance; | |
| } | |
| } |
This file contains hidden or 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
| public class CarTester { | |
| public static void main(String[] args){ | |
| Car myCar = new Car(20); // 20 kilometers per litter | |
| myCar.addGas(40); // Add gasoline 40 litters | |
| myCar.drive(100); // Drive 100 kilometers | |
| double gasLeft = myCar.getGasInTank(); | |
| System.out.println(gasLeft); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment