-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
35 lines (25 loc) · 933 Bytes
/
Copy pathCar.java
File metadata and controls
35 lines (25 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
*
* Tom Abraham
* period #1
*/
public class Car {//This is used of instantiating the instance variables
private int startOdometer;
private int currentOdometer;
private double gallonsConsumed;
public Car(){//Default constructor used for calling in the driver
}
public void fillUp(int currentOd, int startOd, double gallonsUsed) {//This parameter constructor is used for initializing all the instance variables
currentOdometer = currentOd;
gallonsConsumed = gallonsUsed;
startOdometer = startOd;
}
public double calculateMPG(){//This method is used for calculating the miles per gallon.
double MilesPerGallon = (currentOdometer - startOdometer) / gallonsConsumed;
return MilesPerGallon;
}
public void resetMPG() {//This method is used for resetting the variables so that the mpg can be calculated once again
gallonsConsumed = 0;
startOdometer = currentOdometer;
}
}//end class