I have finished coding (well thought I had finished coding) a program in java but the only problem is that it is giving me the correct input but it isn't in the columns properly.. an example picture has been attached to this post.
As you can see in the picture the column headings do not line up properly with the results. This is because of the word length of the results. I want to know how I can make everything move into pretty columns without having to shorten all the names (as that is not going to happen in the real world).
My code for printing the headings (Code, Brand, Name, Price) is:
public void listProducts() {
System.out.printf("%-8s %-8s %8s %8s \n", "Code", "Brand", "Name", "Price");
for (int index = 0; index < productList.size(); index++)
printProductDetails(productList.get(index));
}