I am nearly done with my project (technically it's finished), but I am having a big problem with little detail such as output formatting. I am fairly new to JAVA and would apreciatte any help you can provide.
I need to output 2 arrays (String and Int) in some sort of table format. Example: England 4.6 USA 2.6 Japan 7.8 etc
I need exact spacing between the characters. I'll give you one part of my code: (I can apply the logic to the rest of the program)
double beerStrenghts [] = new double [10];
for(int x = 0; x < beerStrenghts.length; x++){
beerStrenghts[x] = beerStrenghts()[x];
}
String beerName [] = new String [10];
for(int x = 0; x < beerName.length; x++){
beerName[x] = (beerName()[x]);
}
String lookup;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter search criteria. Min 3 characters.");
lookup = keyboard.nextLine();
while(lookup.length() < 3){
System.out.println("Please enter at least 3 characters");
lookup = keyboard.nextLine();
}
Formatter fmt = new Formatter();
int indexInt;
boolean found;
for(int x = 0; x< beerName.length; x++){
found = beerName[x].toUpperCase().contains(lookup.toUpperCase());
if(found){
fmt.format("%12s%3d",beerName[x], beerStrenghts[x]);
System.out.println(fmt);
}
}
}
public static String [] beerName(){
String[] beerName = new String[10];
beerName[0] = "Heineken";
beerName[1] = "Bud Light";
beerName[2] = "Coors Light";
beerName[3] = "Leffe Blonde";
beerName[4] = "Budweiser";
beerName[5] = "Erdinger Non-Alcoholic";
beerName[6] = "Bud Premier Select";
beerName[7] = "Corona";
beerName[8] = "Barefoot Bohemian";
beerName[9] = "3 Monts";
return beerName;
}
public static double [] beerStrenghts(){
double beerStrenghts [] = new double [10];
beerStrenghts[0] = 4.0;
beerStrenghts[1] = 4.2;
beerStrenghts[2] = 4.3;
beerStrenghts[3] = 6.6;
beerStrenghts[4] = 5.0;
beerStrenghts[5] = 0.0;
beerStrenghts[6] = 7.4;
beerStrenghts[7] = 4.6;
beerStrenghts[8] = 4.0;
beerStrenghts[9] = 8.5;
return beerStrenghts;