1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
   | public class ClassTest
{
    private enum t_imc {
        imc_01,
        imc_02,
        imc_03,
        imc_04,
        imc_05,
        imc_06,
        imc_07
    };
 
 
    public String imc_toString_fr(double imc) {
        String str;
 
        switch( get_imc_enum(imc) ) {
        case imc_01: str = new String("d\u00E9nutritionn\u00E9(e)"); break;
        case imc_02: str = new String("maigre"); break;
        case imc_03: str = new String("poids id\u00E9al"); break;
        case imc_04: str = new String("surpoids"); break;
        case imc_05: str = new String("ob\u00E8se mod\u00E9r\u00E9e"); break;
        case imc_06: str = new String("ob\u00E8se s\u00E9v\u00E8re"); break;
        case imc_07: str = new String("ob\u00E8se morbide ou massive"); break;
        default: str = new String("[???]"); break;
        }
 
        return str;
    }
 
 
    static public double get_imc_double(double poids, double taille) {
        return (poids / (taille * taille));
    }
 
 
    private t_imc get_imc_enum(double imc) {
        return ((imc >= 16.5)? ((imc >= 18.5)? ((imc >= 25)? ((imc >= 30)? ((imc >= 35)? ((imc >= 40)? t_imc.imc_07: t_imc.imc_06): t_imc.imc_05): t_imc.imc_04): t_imc.imc_03): t_imc.imc_02): t_imc.imc_01);
    }
 
 
//  main  
 
    public static void main(String[] args) {
        ClassTest test = new ClassTest();
 
        double imc, poids, taille;
 
        poids = 95; taille = 1.81;
        imc = get_imc_double(poids, taille);
 
        System.out.println("Pour une taille " + taille + " cm, et un poids de " + poids + " kg, votre IMC est : " + imc + "donc " + test.imc_toString_fr(imc));
 
        poids = 48; taille = 1.69;
        imc = get_imc_double(poids, taille);
 
        System.out.println("Pour une taille " + taille + " cm, et un poids de " + poids + " kg, votre IMC est : " + imc + "donc " + test.imc_toString_fr(imc));
 
        poids = 61; taille = 1.57;
        imc = get_imc_double(poids, taille);
 
        System.out.println("Pour une taille " + taille + " cm, et un poids de " + poids + " kg, votre IMC est : " + imc + "donc " + test.imc_toString_fr(imc));
 
        poids = 140; taille = 2.04;
        imc = get_imc_double(poids, taille);
 
        System.out.println("Pour une taille " + taille + " cm, et un poids de " + poids + " kg, votre IMC est : " + imc + "donc " + test.imc_toString_fr(imc));
    }
} | 
Partager