help me with my beginner java programming homework please?

okay so I have most of it done but when I compile it, it won't turn out the way my teacher wants it to be. For example it always says The FIRST leter grade for A. So if a students grade was a B, it will still say the FIRST letter grade. I don't know if that makes any sense but pretty much I don't want it to print first for A, second for B, third for C and so on..How do I do that?

import java.util.Scanner;

public class AverageAndGrade

{

public static void main(String[] args)

{

Scanner keyboard = new Scanner(System.in);

double scoreOne;

double scoreTwo;

double scoreThree;

double scoreFour;

double scoreFive;

char letter1,letter2,letter3,letter4,letter5;

double average;

System.out.println("Please enter the first score between 0 and 100: ");

scoreOne = keyboard.nextDouble();

System.out.println("Please enter the second score between 0 and 100: ");

scoreTwo = keyboard.nextDouble();

System.out.println("Please enter the third score between 0 and 100: ");

scoreThree = keyboard.nextDouble();

System.out.println("Please enter the forth score between 0 and 100: ");

scoreFour = keyboard.nextDouble();

System.out.println("Please enter the fifth score between 0 and 100: ");

scoreFive = keyboard.nextDouble();

keyboard.nextLine();

average = scoreOne;

determineGrade(average);

average = scoreTwo;

determineGrade(average);

average = scoreThree;

determineGrade(average);

average = scoreFour;

determineGrade(average);

average = scoreFive;

determineGrade(average);

System.out.println();

average = calcAverage(scoreOne, scoreTwo, scoreThree, scoreFour, scoreFive);

System.out.println("The average test score is: " + average);

System.out.print("The average grade is: " );

determineGrade(average);

}

public static double calcAverage(double scoreOne, double scoreTwo, double scoreThree, double scoreFour, double scoreFive)

{

double average = ((scoreOne + scoreTwo + scoreThree + scoreFour + scoreFive) / 5);

return average;

}

public static double determineGrade(double average)

{

char grade;

if (average>=90)

{

grade = 'A';

System.out.println("The first letter grade is: " + grade);

}

else if (average>=80)

{

grade = 'B';

System.out.println("The second letter grade is: " + grade);

}

else if (average>=70)

{

grade = 'C';

System.out.println("The third letter grade is: " + grade);

}

else if (average>=60)

{

grade = 'D';

System.out.println("The fourth letter grade is: " + grade);

}

else if (average<60)

{

grade= 'F';

System.out.println("The fifth letter grade is: " + grade);

}

return 0;

}

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    1. In the method determineGrade() have it return a char which is the grade. In your version, it always returns zero.

    2. Review my solution. Look carefully at the comments that I added that have <<<< in them.

    Here is my solution. Carefully study the differences between the two solutions.

    http://ideone.com/hZH5co

  • One
    Lv 6
    8 years ago

    This is the output i received after executing your code. Please explain what else you want

    Please enter the first score between 0 and 100:

    25

    Please enter the second score between 0 and 100:

    12

    Please enter the third score between 0 and 100:

    178

    Please enter the forth score between 0 and 100:

    45

    Please enter the fifth score between 0 and 100:

    34

    The fifth letter grade is: F

    The fifth letter grade is: F

    The first letter grade is: A

    The fifth letter grade is: F

    The fifth letter grade is: F

    The average test score is: 58.8

    The average grade is: The fifth letter grade is: F

Still have questions? Get your answers by asking now.