0

I haven't finished writing this and im confused on how to do this. i need to output the averages together and indiviually(major,minor,other)-NOT FINISHED need input on what to do. you have to ask the user to continuing entering grades until they enter a negative number.

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));
}

}

  • Looks like you’ve got a good start. What is the problem? – AJNeufeld Nov 30 '17 at 05:38
  • Allow me to anticipate: `DivisionByZeroException` when you test with “major” data, and you don’t understand why? That would only happen if `count` was zero, but `count` has to be incremented if the first test passes? So why wouldn’t the test pass? Unless, there was something you’ve forgotten about comparing `String` objects. Something about `==` not working for some reason? And something that you could use instead? – AJNeufeld Nov 30 '17 at 05:56

0 Answers0