So I'm in the mood for experimenting and am stuck on making my program look pretty. When I run this program:
Code:
public class ToString { //It's called ToString because I made this class to learn about it. I'm conserving time.
private String Band;
private String genre;
private static int bands=0;
public ToString(String bn, String gn) {
Band = bn;
genre = gn;
bands++;
if (genre.length() >= 10) {
System.out.printf("Band: %s\t Their genre: %s\t\t Number of bands: %d\n", Band, genre, bands );
}
else {
System.out.printf("Band: %s\t Their genre: %s\t Number of bands: %d\n", Band, genre, bands );
}
}
}
I get the issue where the text isn't inline on the last variable. The If statement I thought would be the cure, but the problem is, is that genre has multiple values, so while Rammstein and Death go ahead an extra tab, Gojira doesn't.
Main class so you know what I'm talking about:
Code:
class Prac1 {
public static void main(String[] args) {
for (Prac2 games: Prac2.values())
System.out.printf("Game: %s\t Fun: %s\t Content: %s\n", games, games.getFun(), games.getContent());
System.out.println("***And now for the set range!***");
for (Prac2 games: EnumSet.range(Prac2.WoW, Prac2.GW2))
System.out.printf("Game: %s\t Fun: %s\t Content: %s\n", games, games.getFun(), games.getContent());
System.out.println("\n***Metal Bands!***\n");
ToString bnds1=new ToString("Rammstein", "New German Industrial Metal"); //Genre string length = 26
ToString bnds2=new ToString("Death", "Death metal");
ToString bnds3=new ToString("Gojira", "Too many");
}
}
When this is run, the output looks like this:
Code:
Band: Rammstein Their genre: New German Industrial Metal Number of bands: 1
Band: Death Their genre: Death metal Number of bands: 2
Band: Gojira Their genre: Too many Number of bands: 3
So how would I get it so that 'Number of bands' lines up with each other like the last two variables?
---------- Post added 2012-11-12 at 04:16 PM ----------
Also the code before was just practising with Enum.