Web Analytics Made Easy -
StatCounter Java Grading Program help - CodingForum

Announcement

Collapse
No announcement yet.

Java Grading Program help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java Grading Program help

    I have everything done...but me and my friends in class cant figure out how to do the high and low score (range) i think my teacher said something about it beint just simple if statements but i figure it out....if anyone has any ideas let me know
    // 80 Point Version
    //
    // Write a program to read a list of exam scores (numbers in the range 0 .. 100)
    // and to output the total number of grades and the number of grades in each
    // letter-grade category.(90-100=A, 80-89=B, 75-79=C, 70-74=D, 0-69=F).

    // Sample Output
    // Enter a grade (-1 to quit) --> 89
    // Enter a grade (-1 to quit) --> 70
    // Enter a grade (-1 to quit) --> 56
    // Enter a grade (-1 to quit) --> 113
    // 113 is an invalid grade
    // Enter a grade (-1 to quit) --> 100
    // Enter a grade (-1 to quit) --> 50
    // Enter a grade (-1 to quit) --> 77
    // Enter a grade (-1 to quit) --> 40
    //
    // Total number of grades: 7
    // Number of A's: 1
    // Number of B's: 1
    // Number of C's: 1
    // Number of D's: 1
    // Number of F's: 3


    // 100 Point version
    // Also print out the highest and lowest grades, the average, and percentage
    // of total for each letter grade.

    // 100 point version sample output
    // Enter a grade (-1 to quit) --> 89
    // Enter a grade (-1 to quit) --> 70
    // Enter a grade (-1 to quit) --> 56
    // Enter a grade (-1 to quit) --> 113
    // 113 is an invalid grade
    // Enter a grade (-1 to quit) --> 100
    // Enter a grade (-1 to quit) --> 50
    // Enter a grade (-1 to quit) --> 77
    // Enter a grade (-1 to quit) --> 40
    //
    // Total number of grades: 7
    // Number of A's: 1
    // Number of B's: 1
    // Number of C's: 1
    // Number of D's: 1
    // Number of F's: 3
    // Percentage of A's: 14.2857142%
    // Percentage of B's: 14.2857142%
    // Percentage of C's: 14.2857142%
    // Percentage of D's: 14.2857142%
    // Percentage of F's: 4285714285%
    // Range:
    // Highest Score: 100
    // Lowest Score: 40
    // Average Score: 68.857142857142

    import learning.*;

    public class GradeStats
    {
    public static void main(String[] args)
    {
    double grade;
    double average;
    double sum = 0;
    double count = 0;
    int numA = 0;
    int numB = 0;
    int numC = 0;
    int numD = 0;
    int numF = 0;
    int high = 0;
    int low = 0;
    double pa;
    double pb;
    double pc;
    double pd;
    double pf;

    do
    {
    System.out.print("Enter a grade(-1 to quit)-->");
    grade = LearningIO.readDouble();
    if(grade>100)
    System.out.println("Grade must be 0-100");
    }
    while(grade>100);

    while(grade>0)
    {
    sum+=grade;
    count+=1;
    if(grade >= 90)
    numA+=1;
    else if(grade >= 80)
    numB+=1;
    else if(grade >= 75)
    numC+=1;
    else if(grade >= 70)
    numD+=1;
    else if(grade >= 0)
    numF+=1;
    do
    {
    System.out.print("Enter a grade(-1 to quit)-->");
    grade = LearningIO.readDouble();
    if(grade>100)
    System.out.println("Grade must be 0-100");
    }
    while(grade>100);
    }

    System.out.println("Total number of grades " +count);
    System.out.println("Number of A's "+numA);
    System.out.println("Number of B's "+numB);
    System.out.println("Number of C's "+numC);
    System.out.println("Number of D's "+numD);
    System.out.println("Number of F's "+numF);

    pa = (numA/count)*100;
    System.out.println("Percentage of A's "+pa+"%");
    pb = (numB/count)*100;
    System.out.println("Percentage of A's "+pb+"%");
    pc = (numC/count)*100;
    System.out.println("Percentage of A's "+pc+"%");
    pd = (numD/count)*100;
    System.out.println("Percentage of A's "+pd+"%");
    pf = (numF/count)*100;
    System.out.println("Percentage of A's "+pf+"%");

    System.out.println("Range:");
    if()
    System.out.println("High Score:"+high);
    System.out.println("Low Score:"+low);


    average = sum/count;
    System.out.println("Your average is " +average);
    }
    }

  • #2
    Originally posted by guitarslayer View Post
    I have everything done...but me and my friends in class cant figure out how to do the high and low score (range) i think my teacher said something about it beint just simple if statements but i figure it out....if anyone has any ideas let me know
    // 80 Point Version
    //
    // Write a program to read a list of exam scores (numbers in the range 0 .. 100)
    // and to output the total number of grades and the number of grades in each
    // letter-grade category.(90-100=A, 80-89=B, 75-79=C, 70-74=D, 0-69=F).

    // Sample Output
    // Enter a grade (-1 to quit) --> 89
    // Enter a grade (-1 to quit) --> 70
    // Enter a grade (-1 to quit) --> 56
    // Enter a grade (-1 to quit) --> 113
    // 113 is an invalid grade
    // Enter a grade (-1 to quit) --> 100
    // Enter a grade (-1 to quit) --> 50
    // Enter a grade (-1 to quit) --> 77
    // Enter a grade (-1 to quit) --> 40
    //
    // Total number of grades: 7
    // Number of A's: 1
    // Number of B's: 1
    // Number of C's: 1
    // Number of D's: 1
    // Number of F's: 3


    // 100 Point version
    // Also print out the highest and lowest grades, the average, and percentage
    // of total for each letter grade.

    // 100 point version sample output
    // Enter a grade (-1 to quit) --> 89
    // Enter a grade (-1 to quit) --> 70
    // Enter a grade (-1 to quit) --> 56
    // Enter a grade (-1 to quit) --> 113
    // 113 is an invalid grade
    // Enter a grade (-1 to quit) --> 100
    // Enter a grade (-1 to quit) --> 50
    // Enter a grade (-1 to quit) --> 77
    // Enter a grade (-1 to quit) --> 40
    //
    // Total number of grades: 7
    // Number of A's: 1
    // Number of B's: 1
    // Number of C's: 1
    // Number of D's: 1
    // Number of F's: 3
    // Percentage of A's: 14.2857142%
    // Percentage of B's: 14.2857142%
    // Percentage of C's: 14.2857142%
    // Percentage of D's: 14.2857142%
    // Percentage of F's: 4285714285%
    // Range:
    // Highest Score: 100
    // Lowest Score: 40
    // Average Score: 68.857142857142

    import learning.*;

    public class GradeStats
    {
    public static void main(String[] args)
    {
    double grade;
    double average;
    double sum = 0;
    double count = 0;
    int numA = 0;
    int numB = 0;
    int numC = 0;
    int numD = 0;
    int numF = 0;
    int high = 0;
    int low = 0;
    double pa;
    double pb;
    double pc;
    double pd;
    double pf;

    do
    {
    System.out.print("Enter a grade(-1 to quit)-->");
    grade = LearningIO.readDouble();
    if(grade>100)
    System.out.println("Grade must be 0-100");
    }
    while(grade>100);

    while(grade>0)
    {
    sum+=grade;
    count+=1;
    if(grade >= 90)
    numA+=1;
    else if(grade >= 80)
    numB+=1;
    else if(grade >= 75)
    numC+=1;
    else if(grade >= 70)
    numD+=1;
    else if(grade >= 0)
    numF+=1;
    do
    {
    System.out.print("Enter a grade(-1 to quit)-->");
    grade = LearningIO.readDouble();
    if(grade>100)
    System.out.println("Grade must be 0-100");
    }
    while(grade>100);
    }

    System.out.println("Total number of grades " +count);
    System.out.println("Number of A's "+numA);
    System.out.println("Number of B's "+numB);
    System.out.println("Number of C's "+numC);
    System.out.println("Number of D's "+numD);
    System.out.println("Number of F's "+numF);

    pa = (numA/count)*100;
    System.out.println("Percentage of A's "+pa+"%");
    pb = (numB/count)*100;
    System.out.println("Percentage of A's "+pb+"%");
    pc = (numC/count)*100;
    System.out.println("Percentage of A's "+pc+"%");
    pd = (numD/count)*100;
    System.out.println("Percentage of A's "+pd+"%");
    pf = (numF/count)*100;
    System.out.println("Percentage of A's "+pf+"%");

    System.out.println("Range:");
    if()
    System.out.println("High Score:"+high);
    System.out.println("Low Score:"+low);


    average = sum/count;
    System.out.println("Your average is " +average);
    }
    }
    What's is this if statement doing?

    Code:
    		if()
    		System.out.println("High Score:"+high);
    When do you set high and low?

    Code:
    	pa = (numA/count)*100;
    		System.out.println("Percentage of A's "+pa+"%");
    		pb = (numB/count)*100;
    		System.out.println("Percentage of A's "+pb+"%");
    		pc = (numC/count)*100;
    		System.out.println("Percentage of A's "+pc+"%");
    		pd = (numD/count)*100;
    		System.out.println("Percentage of A's "+pd+"%");
    		pf = (numF/count)*100;
    		System.out.println("Percentage of A's "+pf+"%");
    That code wont work for what you want I suspect. Why? Well let's look at it.

    Count is the number of grades. That number will always be either higher or equal to the number of a letter.

    Thusly you will always get 0. Why? Integer division of course!!

    2/3 = 0
    3/2 = 1
    2/2 = 1
    etc..

    If you want to think of it in a basic term, you can think of it as the computer chops off from the decimal place on and keeps the whole numbers.

    So how do you get percentages? Well you can either Cast it, or you can force the numbers to become doubles. I suggest casting though.

    Hope that helps.
    "To iterate is human, to recurse divine." -L. Peter Deutsch

    Comment

    Working...
    X