O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

With the three enum types in place, we can calculate the vehicle speed of all the possible combinations of the given driving conditions:

public static void main(String... arg) {  double timeSec = 10.0;  String[] roadConditions = { RoadCondition.WET.toString(),                               RoadCondition.SNOW.toString() };  String[] tireConditions = { TireCondition.NEW.toString(),                               TireCondition.WORN.toString() };  for(String rc: roadConditions){    for(String tc: tireConditions){      Properties drivingCond = new Properties();      drivingCond.put(DrivingCondition                      .ROAD_CONDITION.toString(), rc);      drivingCond.put(DrivingCondition                      .TIRE_CONDITION.toString(), tc);      SpeedModel speedModel = FactorySpeedModel                      .generateSpeedModel(drivingCond); Car car = FactoryVehicle.buildCar(4, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required