I have a school task in which I have to create a code that creates and fills an array, then with those data. I have to calculate BMI, decide if their BMI is normal and the names of the people whose BMI is normal should be outputted to the console.
Where I'm stuck is when calling the method to output the names, I can't find out what would be the correct arguments. There might be other problems with it, correct me in that case as well.
Here is my code:
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
class TreatedPerson {
String name = "";
int age;
int height;
int weight;
@Override
public String toString() {
return "Name: " + name + " \tAge: " + age + " \tHeight: " + height + " \tWeight: " + weight;
}
}
public class B1 {
static void fillTreatedPerson(ArrayList<TreatedPerson> treatedpeople, int db) {
Random rnd = new Random();
for (int i = 0; i < db; i++) {
TreatedPerson tp = new TreatedPerson();
tp.name = ("Szemely_" + (i + 1));
tp.age = rnd.nextInt(99 - 10 + 1) + 10;
tp.height = rnd.nextInt(200 - 150 + 1) + 150;
tp.weight = rnd.nextInt(150 - 40 + 1) + 40;
treatedpeople.add(tp);
}
}
static void outputTreatedPerson(ArrayList<TreatedPerson> treatedpeople) {
for (TreatedPerson tp : treatedpeople) {
System.out.println(tp);
}
}
static double BMI(TreatedPerson tp) {
return tp.weight / (tp.height * tp.height);
}
static boolean normalBMI(double bmi) {
boolean bmindex = false;
if (bmi > 18.5 && bmi < 24.99) {
return bmindex = true;
}
return bmindex;
}
static void ifnormalBMI(TreatedPerson tp, boolean normalBMI) {
if (normalBMI) {
System.out.println(tp.name);
}
}
public static void main(String[] args) {
ArrayList<TreatedPerson> treatedpeople = new ArrayList<>();
fillTreatedPerson(treatedpeople, 5);
outputTreatedPerson(treatedpeople);
ifnormalBMI();
}
}