I am trying to add more user friendly descriptions for multiple enum members in the same class. Right now I just have each enum returned in lowercase:
public enum Part {
ROTOR, DOUBLE_SWITCH, 100_BULB, 75_BULB,
SMALL_GAUGE, LARGE_GAUGE, DRIVER;
private final String description;
Part() {
description = toString().toLowerCase();
}
Part(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
Is there a way to give each enum value a more user-friendly name which I can display via the toString() for each Part member? For example when I interate over the Parts:
for (Part part : Part.values()) {
System.out.println(part.toString());
}
rather than getting the literal list:
ROTOR
DOUBLE_SWITCH
100_BULB
75_BULB
SMALL_GAUGE
LARGE_GAUGE
DRIVER
I am hoping to give meaningful descriptions to each item so I can output something like:
Standard Rotor
Double Switch
100 W bulb
75 W bulb
Small Gauge
Large Gauge
Torque Driver
So I was wondering if there is a way to give those meaningful descriptions for each enum member in my Part enum class.
Many thanks