I was working on a Java lesson and the section was on Enumerations. I have this in my Enum:
public enum tuna {
Camaro("Orange", "1968"),
Silverado("Red","1996"),
Sierra("Black","2007"),
Equinox("Silver","2011");
private final String color;
private final String year;
tuna(String carColor, String age){
color = carColor;
year = age;
}
public String getColor(){
return color;
}
public String getYear(){
return year;
}
}
and this in my Java Class that prints it out:
for(tuna cars: tuna.values()){
System.out.printf("%s\t\t%s\t\t%s\n", cars, cars.getColor(), cars.getYear()
Which prints out:

See how the “Red” and “1996” for the Silverado are way over on the right (because “Silverado” is longer than the other words)?
Well how can I fix it so the details for long words are equally spaced as the rest?
P.S. if I shorten “Silverado” to “Silver”, it’s normal:

I’d suggest not using tabs but string formatting, i.e. use
System.out.format(...)and calculate the length of each format specifier by getting the length of the longest name. Then build the format string dynamically.Example:
Output: