I've been asked to create a program that takes items from a text file and displays them in a list formatted "LastName, FirstName ZipCode" where the ZIP codes all align on the right and the Last and First names are only separated by a comma and a space.
I'm having no problem getting everything to list, the only problem I'm running into is aligning the ZIP codes.
Currently this is what I have written for the output format:
System.out.printf("%s, %s %s\n", fileList.get(lastName), fileList.get(i), fileList.get(zipCode));
And my output is this (as expected):
Baron, Steven 84521
Chill, Robert 63258
Blanthony, Stacy 84815
Wick, John 78412
Yule, Katherine 42136
(etc)
Here's how I want it to look:
Baron, Steven 84521
Chill, Robert 63258
Blanthony, Stacy 84815
Wick, John 78412
Yule, Katherine 42136
I was thinking maybe I could do something where I count the total number of characters from the LastName all the way to the ZIP code and then have that subtracted from a very large number of spaces between the LastName and ZipCode, but I wasn't sure how to do that since it would be bouncing between Strings and Ints. Also, I imagine there is a much simpler solution that I'm just not aware of.
Any help is appreciated!
Thank you,
CCoolant