-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorySpeedModel.java
More file actions
26 lines (21 loc) · 887 Bytes
/
Copy pathFactorySpeedModel.java
File metadata and controls
26 lines (21 loc) · 887 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
package interfaces.a;
import java.util.Properties;
public class FactorySpeedModel {
public static SpeedModel generateSpeedModel(Properties drivingConditions) {
return new SpeedModelImpl(drivingConditions);
}
private static class SpeedModelImpl implements SpeedModel {
private Properties drivingConditions;
private SpeedModelImpl(Properties drivingConditions) {
this.drivingConditions = drivingConditions;
}
public double getSpeedMph(double timeSec, int weightPounds, int horsePower) {
String roadCondition = drivingConditions.getProperty("roadCondition", "Dry");
String tireCondition = drivingConditions.getProperty("tireCondition", "New");
double v = 2.0 * horsePower * 746;
v = v * timeSec * 32.174 / weightPounds;
return Math.round(Math.sqrt(v) * 0.68) - (roadCondition.equals("Dry") ? 2 : 5)
- (tireCondition.equals("New") ? 0 : 5);
}
}
}