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...

Fans who love using the metric system of units can now take advantage of the new method:

public static void main(String... arg) {  int horsePower = 246;  int payload = Truck.convertKgToPounds(1500);  int vehicleWeight = Truck.convertKgToPounds(1800);  Truck truck = FactoryVehicle            .buildTruck(payload, vehicleWeight, horsePower);  System.out.println("Payload in pounds: " + truck.getPayloadPounds());  int kg = truck.getPayloadKg();  System.out.println("Payload converted to kg: " + kg);  System.out.println("Payload converted back to pounds: " +                      Truck.convertKgToPounds(kg));}

The results will be as follows:

The value 1,502 is close to ...

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