In: Computer Science
rite a method with the following header:
public static void showGradeDistribution(int a, int b, int c, int d,
int f)
It should print a graph (using asterisks) for each of the letters entered in the reverse order of the
parameter list and with a label. In addition, if A and B grades sum is equal or exceeds that of grades C
and D and F, the message “Strong class!” should be displayed. For example a method call of:
showGradeDistribution(5,7,4,4,3);
Would print:
A: *****
B: *******
C: ****
D: ****
F: ***
Strong clas
public class GradeGraph {
public static void main(String[] args) {
showGradeDistribution(5, 7, 4, 4, 3); //supply values for grades
}
//function that takes grades as parameters
public static void showGradeDistribution(int a, int b, int c, int d, int f) //function that takes grades as parameters
{
System.out.print("A: "); //print asterisks for A grade
for(int i = 0; i<a; i++) //loop until a
{
System.out.print('*'); //print asterisk for number of times A is received
}
System.out.println();
System.out.print("B: "); //print asterisks for B grade
for(int i = 0; i<b; i++)
{
System.out.print('*');
}
System.out.println();
System.out.print("C: "); //print asterisks for C grade
for(int i = 0; i<c; i++)
{
System.out.print('*');
}
System.out.println();
System.out.print("D: "); //print asterisks for D grade
for(int i = 0; i<d; i++)
{
System.out.print('*');
}
System.out.println();
System.out.print("F: "); //print asterisks for F grade
for(int i = 0; i<f; i++)
{
System.out.print('*');
}
System.out.println();
if((a+b)>=(c+d+f)) //as per question if sum of a and b is >= sum of c d and f
{
System.out.println("Strong class!"); //print strong class
}
}
}
OUTPUT OF THE PROGRAM ON INPUT: showGradeDistribution(5,7,4,4,3);
OUTPUT OF THE PROGRAM ON INPUT: showGradeDistribution(2,7,4,4,3);
Notice here strong class is missing.
Thanks and please do not forget to leave a thuumbs up :)