Only using three methods (including main) and an array of 10 whole numbers, I need to create a program that does these stuff:
- Count how many people who passed the exam.
- Print the statistics. (eg. grade A, B, C, D, E...)
- How many people passed or failed their exam.
Here's what I have right now. The only problem I have is that I don't know how to return multiple values.
public class Array10PassFail
public static int countPass (int [] num)
{
int count = 0;
int counter = 0;
for (int i = 0; i < num.length; i++)
{
if (num [i] >= 50)
{
count++;
}
else if (num [i] < 50)
{
counter++;
}
}
return count;
}
public static int printStats (int [] num)
{
int aTotal = 0, bTotal = 0,cTotal = 0, dTotal = 0, eTotal = 0;
for (int i = 0; i < num.length; i++)
{
if (num[i] >= 80)
{
aTotal++;
}
else if (num[i] >= 70)
{
bTotal++;
}
else if (num[i] >= 60)
{
cTotal++;
}
else if (num[i] >= 50)
{
dTotal++;
}
else if (num[i] < 50)
{
eTotal++;
}
}
return aTotal;
}
public static void main (String [] args)
{
Scanner sc = new Scanner(System.in);
int [] num = new int [10];
for (int i = 0; i < num.length; i++)
{
System.out.print("Enter score: ");
num[i] = sc.nextInt();
}
int passf = countPass(num);
System.out.println("There are " + passf + " people who passed and " + ??? + " who failed. ");
}