public enum CountWheels{ Min(2), Mid(3), Max(4); private final int val; private CountWheels(int val){ this.val = val; } public int getCountWheels(){ return val; } public static CountWheels fromNumberToEnum(int number) { try{ for (CountWheels countWheels : CountWheels.values()) { if (countWheels.getCountWheels() == number) { return countWheels; } } }catch(NumberFormatException e){ } return Min; } }