I am creating a java program that will take 10 user input grades from 1-100 and display them as a letter grade, then calculate the percent of how many letter grades there are in total.

The last step is to figure out how to get each letter grade, lets say 5 F's, 2 B's, 2 C's, and 1 A, and get what total percentage of each letter grade there is out of ten so like 50% F's, 20% B's, etc. What do I do next? I assume I have to assign some doubles for the percent to display but my brain is fried right now.

Here is what I have so far:

``````import java.util.Scanner;
public static void main(String[] args)
{

int g1, g2, g3, g4, g5, g6, g7, g8, g9, g10;

System.out.println("Type 10 grades in whole numbers from 0-100");
System.out.println();

Scanner keyboard = new Scanner(System.in);
g1 = keyboard.nextInt( );
g2 = keyboard.nextInt( );
g3 = keyboard.nextInt( );
g4 = keyboard.nextInt( );
g5 = keyboard.nextInt( );
g6 = keyboard.nextInt( );
g7 = keyboard.nextInt( );
g8 = keyboard.nextInt( );
g9 = keyboard.nextInt( );
g10 = keyboard.nextInt( );

if (g1 >= 90) {
} else if (g1 >= 80) {
} else if (g1 >= 70) {
} else if (g1 >= 60) {
} else {
}

if (g2 >= 90) {
} else if (g2 >= 80) {
} else if (g2 >= 70) {
} else if (g2 >= 60) {
} else {
}
if (g3 >= 90) {
} else if (g3 >= 80) {
} else if (g3 >= 70) {
} else if (g3 >= 60) {
} else {
}
if (g4 >= 90) {
} else if (g4 >= 80) {
} else if (g4 >= 70) {
} else if (g4 >= 60) {
} else {
}
if (g5 >= 90) {
} else if (g5 >= 80) {
} else if (g5 >= 70) {
} else if (g5 >= 60) {
} else {
}
if (g6 >= 90) {
} else if (g6 >= 80) {
} else if (g6 >= 70) {
} else if (g6 >= 60) {
} else {
}
if (g7 >= 90) {
} else if (g7 >= 80) {
} else if (g7 >= 70) {
} else if (g7 >= 60) {
} else {
}
if (g8 >= 90) {
} else if (g8 >= 80) {
} else if (g8 >= 70) {
} else if (g8 >= 60) {
} else {
}
if (g9 >= 90) {
} else if (g9 >= 80) {
} else if (g9 >= 70) {
} else if (g9 >= 60) {
} else {
}
if (g10 >= 90) {
} else if (g10 >= 80) {
} else if (g10 >= 70) {
} else if (g10 >= 60) {
} else {
}
}
}``````

## All 7 Replies

put counters in your if-else statements so you can monitor how many A,B,C,D,E,and F you have.

to compute for the percentage, divide the number of times you got each letter by 10.
then multiply by 100%.

for example, you have 5 A's.
5/10 = 0.5 * 100% = 50%;

if you want a copy of the code that I have made, just reply to this post, but i used arrays, so my code will be shorter.

Well what I am having troubles with is getting the count of how many of each grade there is into a variable in order to divide and then multiply. The way I did it takes the user input grade number and divides and multiplies which is incorrect. I assume that the counter stores the count of each letter grade in order to divide by 10, but I can't find anything on assigning variables to a counter in my text book. As far as I know I'm not allowed to use arrays neither unless there is no other possible way of completing this task.

What I was thinking was doing something like

``double gr1 = (g1/10)*100``

which returns as lets say a score of 50 will turn into 500%. I need lets say 5 A's to count at 50%. Care to hint me on that?

first, you should initialize 5 variables to hold your counters and initialize each value to zero.,
say

``int A=0,B=0,C=0,D=0,F=0;``

then, in your if-else statements, put these counters.

``````if (g1 >= 90)
{
A=A+1;
}
else if (g1 >= 80)
{
B=B+1;
}
else if (g1 >= 70)
{
C=C+1;
} else if (g1 >= 60) {
D=D+1;
}
else
{
F=F+1;
}

put these counters in all of your codes.

Hey thanks a lot man that's exactly what I was trying to learn about. That pretty much completes my program. Thanks for helping me, as you can tell I'm still a beginner at programming haha.

you are welcome!:)

If you are interested, there's a better way to approach this because any time you see 10 almost-identical variables and 10 almost-identical blocks of code you should be thinking about using an array and a loop.
So instead of g1, g2, g3 etc you would have `int g[10]` and you main code would look like:

``````for (int i = 0; i<g.length; i++) {
if (g[i] >= 90) {