# Arrays

Having some trouble understanding arrays and how to reference them in my methods. Trying to get going on a program but don't know where to start...

Design and implement a class called Statistics that stores an array of int (grades) and does
various statistical calculations. The class will contain the following methods/operations:

1) highest - returns the highest grade
2) lowest - returns the lowest grade
3) number of grades - returns the number of grades in the array
4) average - returns the average of all the grades
5) print chart - prints out the number of A, B, C, D, F if an
A = 90 - 100
B = 89 - 80
C = 79 - 70
D = 69 - 60
F = < 60

Write a main method to test out this object. The grades to be implemented for this object
are:
int[ ] grades = {79, 93, 51, 50, 70, 75, 97, 97, 98, 62, 67, 80, 69, 44, 84, 93, 94,
76, 61, 96, 97, 58, 37, 83, 60, 59, 54, 56, 82, 33, 83, 62, 64, 26,
74, 71}

Any help is appreciated.
AW

• 1)
int highest = 0;
for(int i = 0;ihighest){
}

2)
int lowest = 100;
for(int i = 0;i= 90){
System.out.println("A");
}
System.out.println("B");
}
System.out.println("C");
}
System.out.println("D");
}
System.out.println("F");
}
}

• : 1)
: int highest = 0;
: for(int i = 0;ihighest){
: }
:
: 2)
: int lowest = 100;
: for(int i = 0;i= 90){
: System.out.println("A");
: }
: System.out.println("B");
: }
: System.out.println("C");
: }
: System.out.println("D");
: }
: System.out.println("F");
: }
: }
:
:

How do I call this in my MAIN? I need to print distro of grades. i.e. 10 A's, 4 B's, 5 C's, etc...

Here's my method:

for(int i = 0;i= 90){
System.out.println("A");
}
System.out.println("B");
}
System.out.println("C");
}
System.out.println("D");
}
System.out.println("F");
}
}

}

Here's my main:

System.out.println("A = 90 - 100 :");
System.out.println("B = 89 - 80 :");
System.out.println("C = 79 - 70 :");
System.out.println("D = 69 - 60 :");
System.out.println("F = < 60 :");

Thank you!
• public static void getLetter(int grades[]){
int counterA = 0;
int counterB = 0;
int counterC = 0;
int counterD = 0;
int counterF = 0;

for(int i = 0;i= 90){
counterA++;
}
counterB++;
}
counterC++;
}
counterD++;
}
counterF++;
}
}
System.out.println("A = 90 - 100 :" + counterA);
System.out.println("B = 89 - 80 :" + counterB);
System.out.println("C = 79 - 70 :" + counterC);
System.out.println("D = 69 - 60 :" + counterD);
System.out.println("F = < 60 :" + counterF);

}
In main if this is same class just call this method

or

• Thank you.
I'm confused as to what the grades[i] comes from. I see that often since I've been working on these array problems. Could you explain?

AW

: public static void getLetter(int grades[]){
: int counterA = 0;
: int counterB = 0;
: int counterC = 0;
: int counterD = 0;
: int counterF = 0;
:
: for(int i = 0;i= 90){
: counterA++;
: }
: counterB++;
: }
: counterC++;
: }
: counterD++;
: }
: counterF++;
: }
: }
: System.out.println("A = 90 - 100 :" + counterA);
: System.out.println("B = 89 - 80 :" + counterB);
: System.out.println("C = 79 - 70 :" + counterC);
: System.out.println("D = 69 - 60 :" + counterD);
: System.out.println("F = < 60 :" + counterF);
:
: }
: In main if this is same class just call this method
:
:
: or
:
:

• "i" is your counter. When you are looping thrue the array you increasing i by 1.That's what i++ does.