-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicle.java
More file actions
54 lines (43 loc) · 1.32 KB
/
Vehicle.java
File metadata and controls
54 lines (43 loc) · 1.32 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Vehicle {
String make;
String model;
VehicleType type;
double tankSize = 0.0; // liters
double tankTime = 0.0; // hourse
double mpg = 0.0;
public static final double LITERS_TO_GALLONS = 0.264172;
public static final double TEST_SPEED = 60.0; // mph
public static int TAB_WIDTH = 8;
public Vehicle(String make,
String model,
VehicleType type,
double tankSize,
double tankTime)
{
this.make = make;
this.model = model;
this.type = type;
this.tankSize = tankSize;
this.tankTime = tankTime;
}
public double mpg() {
return TEST_SPEED * tankTime / (tankSize * LITERS_TO_GALLONS);
}
public boolean meetsStandards() {
return mpg() >= this.type.getFuelStandard();
}
public String getVehicleClass() {
return this.type.getType();
}
public String toString() {
String separator = "\t";
if (model.length() < TAB_WIDTH) separator += "\t";
return make + "\t" + model + separator +
getVehicleClass() + "\t" +
nearestTenth(mpg()) + "\t" +
meetsStandards();
}
private double nearestTenth(double n) {
return ((int)(n * 10.0)) / 10.0;
}
}