// Assume Input.pde is in a tab
void setup()
{
final int MAX_SCORE = 10;
int[] scoreArray = new int[MAX_SCORE+1];
int score;
// This loop isn't really necessary since already all 0
for (int i = 0; i <= MAX_SCORE; i++)
scoreArray[i] = 0;
do
{
score = getInt("Please enter a score out of " + MAX_SCORE);
if (score >= 0 && score <= MAX_SCORE)
scoreArray[score]++;
} while (score >= 0);
println("Score # of Occurrences");
for (int j = 0; j <= MAX_SCORE; j++)
println(j + " " + scoreArray[j]);
int sum = 0, count = 0;
for (int j = 0; j<= MAX_SCORE; j++)
{
sum += scoreArray[j] * j;
count += scoreArray[j];
}
print("The mean score is ");
println(round(1.0 * sum / count * 10) / 10.0);
}
|