-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
39 lines (34 loc) · 830 Bytes
/
Copy pathCar.java
File metadata and controls
39 lines (34 loc) · 830 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
36
37
38
39
/**
* Write a description of class Car here.
*
* @author Luke Bradaric
* @version (a version number or a date)
*/
public class Car
{
// instance variables - replace the example below with your own
public int myStartMiles;
public int myEndMiles;
private double myGallonsUsed;
/**
* Constructor for objects of class Car
*/
public Car(int odometerReading)
{
myStartMiles = odometerReading;
}
public void fillUp(int odometerReading, double gallons)
{
myEndMiles = odometerReading;
myGallonsUsed += gallons;
}
public double calculateMPG()
{
double MPG = (myEndMiles - myStartMiles) / myGallonsUsed;
return MPG;
}
public void resetMPG(){
myStartMiles = myEndMiles;
myGallonsUsed = 0;
}
}