วันจันทร์ที่ 2 พฤศจิกายน พ.ศ. 2558

Lab 8 - (Java) Find/count number of students with BMI > 25


public class Student {

    private String name;
    private int id;
    private int age;
    private int weight;
    private int height;

    public Student(String name, int id, int age, int weight, int height) {

        this.name = name;
        this.id = id;
        this.age = age;
        this.weight = weight;
        this.height = height;

    }

    public void display() {
        System.out.println(this.name);
        System.out.println(this.id);
        System.out.println(this.age);
        System.out.println(this.weight);
        System.out.println(this.height);

    }

    public float get_weight() {
        return this.weight;

    }

    public float get_height() {
        return this.height;

    }

    public static void main(String[] args) {

        Student[] info = {new Student("Bun Tun", 00001, 18, 68, 149),
            new Student("FlukeKnub", 00002, 17, 50, 179),
            new Student("BasBomba", 00003, 20, 44, 188),
            new Student("GaseKiki", 00004, 21, 67, 180),
            new Student("PeeJa", 00005, 15, 88, 155)};

        bmi(info);

    }

    public static void bmi(Student[] e) {

        int count = 0;
        int i = 0;
        float bmi = 0;
        while (i < e.length) {
            bmi = e[i].get_weight() / ((e[i].get_height() / 100) * (e[i].get_height() / 100));

            if (bmi > 25) {
                e[i].display();
                System.out.println();
                count = count + 1;
            }

            i = i + 1;

        }
        System.out.println(count);
    }

}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น