使用循环的加权等级的平均值

时间:2017-11-30 05:14:27

标签: java loops

我还没写完这篇文章,我对如何做到这一点很困惑。我需要一起输出平均值并且单独输出(主要的,次要的,其他的) - 完成 需要输入什么做。你必须要求用户继续输入成绩,直到他们输入负数。

import java.util.Scanner;

public class GradingTwo
{
    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        double grade = 0.0;
        double majAvg = 0.0;
        double minAvg = 0.0;
        double othAvg = 0.0;
        double catMaj = 0.7;
        double catMin = 0.2;
        double catOth = 0.1;
        int count = 0;

    while(grade>=0 && grade<=100)
    {
        System.out.println("Input a numeric grade from 0 to 100: ");
        grade = keyboard.nextDouble();

        if(grade<0)
            break;

        System.out.println("Input a grade category: ");
        String gradeCat = keyboard.next();

        if(gradeCat=="major")
        {
            majAvg+=grade;
            count = count + 1;
        }
    else if(gradeCat=="minor")
            minAvg+=grade;
    else if(gradeCat=="other")
            othAvg+=grade;


        System.out.println();
    }
    System.out.println("Major Average       " + (majAvg/count));
}

}

0 个答案:

没有答案