I would like to know how am I supposed to get the elements from a arraylist in a column(under each other) like this:
BMI: Length: gewicht:
1.69 30 24.25
2.58 55 28.25
This is my code:
@Override
public String toString() {
return String.format("%-17.1f%-15.2f%.2f",lengte, gewicht,bmi);
}
public static void main(String[]args){
ArrayList<BMICalculator> bmilist = new ArrayList<>();
JOptionPane.showMessageDialog(null, String.format("length:%-9sgewicht:%-8sbmi:","","") );
do {
double lengte = getLength("Geef de lengte in Meters:");
double gewicht = getGewicht("Geef het gewicht in Kg:");
BMICalculator bmi = new BMICalculator(lengte, gewicht);
bmi.setBmi(bmi.calculateBMI());
bmilist.add(bmi);
JOptionPane.showMessageDialog(null, String.format("%s", bmi.toString()));
} while(getUserAnswer() == 'J');
JOptionPane.showMessageDialog(null, String.format("%s", bmilist.toString()));
System.out.println(bmilist);
}
This code gives me this: length: gewicht: Bmi: 1,7 80,00 28,01, length: gewicht: bmi: 1,6 55,00 22,03
I dont want that length, gewicht and bmi keeps repeating... help!!!
\t?