Skip to content

Commit

Permalink
Car.java created
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardusa committed Oct 13, 2023
1 parent 7810103 commit 051d550
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Car {
private double mpg;
private double gallons;

public Car(double mpg) {
this.mpg = mpg;
this.gallons = 0;
}

public void addGas(double gallons) {
this.gallons += gallons;
}

public void drive(double miles) {
this.gallons -= miles / mpg;
}

public double getGasInTank() {
return gallons;
}
}
8 changes: 8 additions & 0 deletions CarTester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class CarTester {
public static void main(String[] args) {
Car car = new Car(50);
car.addGas(20);
car.drive(100);
System.out.println(car.getGasInTank() + " gallons left in the tank.");
}
}

0 comments on commit 051d550

Please sign in to comment.