class SpeedFormatterUtil {

    public static int format(final double metersPerSecond, final UnitSystem system) {
        SpeedConverter speedConverter = new SpeedConverter();
        Measurement speedMeterPerSecond = new Measurement(metersPerSecond,
                MeasurementUnit.METERS_PER_SECOND);
        double ret;
        switch (system) {
            case IMPERIAL_UK:
            case IMPERIAL_US:
                ret = speedConverter.convert(speedMeterPerSecond.getValue(),
                        speedMeterPerSecond.getUnit(), MeasurementUnit.MILES_PER_HOUR).getValue();
                break;
            case METRIC:
            default: // metric
                ret = speedConverter.convert(speedMeterPerSecond.getValue(),
                        speedMeterPerSecond.getUnit(), MeasurementUnit.KILOMETERS_PER_HOUR).getValue();
                break;
        }
        return (int) Math.round(ret);
    }

}

class SpeedFormatterUtilTest  {

    private static final double METERS_PER_SECOND_SPEED;
    private static final double KILOMETERS_PER_HOUR_SPEED;
    private static final double MILES_PER_HOUR_SPEED;

    @Test
    public void testFormat() {

        assertEquals(
                SpeedFormatterUtil.format(METERS_PER_SECOND_SPEED, UnitSystem.METRIC),
                (int) KILOMETERS_PER_HOUR_SPEED);
        assertEquals(
                SpeedFormatterUtil.format(METERS_PER_SECOND_SPEED, UnitSystem.IMPERIAL_UK),
                (int) MILES_PER_HOUR_SPEED);
        assertEquals(
                SpeedFormatterUtil.format(METERS_PER_SECOND_SPEED, UnitSystem.IMPERIAL_US),
                (int) MILES_PER_HOUR_SPEED);
    }

}