0

while ループを実行できません。通過し、最後にもう一度患者IDを要求してから終了します

//boolean flag for being in control group
    isInControlGroup = false; 

    Scanner keyboard = new Scanner (System.in);
//prompt for patients I.D., import keyboard.
    System.out.print("Enter Patient id: ");

//read Patients I.D.
    patientId = keyboard.nextLine();

患者 ID は 3 つの数字の後に a または b が続く必要があります。123a のように、ここがめちゃくちゃです。

//finding if patient is a part of the control group
    while(patientId != null && !patientId.equals("")){ //Test for input in the patientID      string. && !patientId.equals("")


//Decide if patient is in control group or not


    if (patientId.charAt(patientId.length()-1)== 'a')
            isInControlGroup = true;
    else if(patientId.charAt(patientId.length()-1)== 'b')
            isInControlGroup = false;
    else
        isInControlGroup = false;

I think it might not be reading the a and b properly.not sure though.
//prompt for the sex of the patient (M or F).
    System.out.println("Enter sex (m/f) for patient:");


//read the sex of the patient
    input = keyboard.nextLine();
    sex = input.charAt(0);    

//Prompt for total cholesterol, HDL, and triglycerides
    System.out.println("Enter total cholesterol, HDL, and triglycerides for patient " + patientId + ":");

//read total cholesterol, HDL, and triglycerides.
    totalCholesterol = keyboard.nextInt();
    HDL = keyboard.nextInt();
    triglycerides = keyboard.nextInt();

//Compute LDL value using LDL=totalCholesterol-HDL-triglycerides/5.
    LDL = totalCholesterol - HDL - triglycerides/ 5; 

//Compute totalChloesterolRatio(decimal division). totalChloesterolRatio=totalChloesterol/HDL
    totalCholesterolRatio = totalCholesterol/(double)HDL;
    totalCholesterolRatio= Math.round(totalCholesterolRatio*10);//Use Math.round.
    totalCholesterolRatio= totalCholesterolRatio/10;//Use 10 to get decimal at tenth spot.

//Update quantitities to compute averages for aggregate report, using a boolean flag.
    if(isInControlGroup==true)
    {
    controlMembers++;//Increment Counter for control members.
    controlLdlTotal += LDL;
    controlRatios += totalCholesterolRatio;
    }

    if(isInControlGroup== false) //If isInControlGroup is false, it adds counts to the treatment group.
    {
    treatmentMembers++;//Increment counter for treatment members.
    treatmentLdlTotal += LDL;
    treatmentRatios += totalCholesterolRatio;
    }





//Determine the  totalCholesterol classification
    if (totalCholesterol >= 240)
    totalChloesterolClassification = "HIGH";

    else if (totalCholesterol >= 200)
        totalChloesterolClassification = "BORDERLINE HIGH";

    else if (totalCholesterol < 200)
        totalChloesterolClassification = "DESIRABLE";

//Determine HDL classification
    switch(sex)
    {   

    case 'm'://When the sex is male.
    case 'M':
        if(HDL<40)
            hdlClassification="LOW";
        else if(HDL<=59)
            hdlClassification="AVERAGE";
        else if(HDL>=60)
            hdlClassification ="HIGH";
        break;
    case 'w'://When sex is female.
    case 'W':
        if(HDL<50)
            hdlClassification = "LOW";
        else if(HDL<=59)
            hdlClassification="AVERAGE";
        else if(HDL>=60)
            hdlClassification="HIGH";
    break;
    }
//Determine LDL classification 
    if(LDL >= 160)
    LDLClassification = "HIGH";

    if(LDL >= 130 && LDL <= 159 )
        LDLClassification = "BORDERINE HIGH";

    if(LDL >= 100 && LDL <= 129)
        LDLClassification = "NEAR OPTIMAL";

    if(LDL >= 0 && LDL < 100)
        LDLClassification = "OPTIMAL";


//Determine triglycerides classification
    if (triglycerides >= 200)
        triglyceridesClassification = "HIGH";

        else if (triglycerides >= 199)
            triglyceridesClassification = "BORDERLINE HIGH";

        else if (triglycerides < 150)
            triglyceridesClassification = "DESIRABLE";


//Determine totalChloestrol/HDL Ratio classification
    if (totalCholesterolRatio >= 5.1)
        totalCholesterolRatioClassification = "INCREASED RISK";

        else if (totalCholesterolRatio >= 3.3)
            totalCholesterolRatioClassification = "AVERAGE RISK";

        else if (totalCholesterolRatio < 3.3)
            totalCholesterolRatioClassification = "DECREASED RISK";


System.out.println("Lipid Profile for Patient "+ patientId);
System.out.println("Total cholesterol: " + totalCholesterol + " " +     totalChloesterolClassification );
System.out.println("HDL: "+ HDL+ " " + hdlClassification);
System.out.println("LDL:" + LDL + " "+ LDLClassification);
System.out.println("Triglycerides: " + triglycerides + " " + triglyceridesClassification );
System.out.println("Ratio: " + totalCholesterolRatio + " " + totalCholesterolRatioClassification );

2 番目の ID の後、これがすべて表示されます。

patientId=null;
System.out.print("Enter Patient id: ");
patientId = keyboard.nextLine();
keyboard.nextLine();

}   //end of loop

ID の入力を求めるプロンプトが再度表示され、終了します。

4

1 に答える 1

0

ループの一番下には、余分なものがありますkeyboard.nextLine()

于 2013-10-15T14:41:13.397 に答える