Help with Structure
Write a short program in java to iterate over a structure and print out the names of all users which have a score less than 70.
At the end of the structure, also print out the average score of all users who scored 70 or higher.
Assume a global function/procedure called print which prints all parameters passed to it and that the structure is called Structure.
Structure Prototype = [[Name1, Score1], [Name2, Score2], …]
Example Structure = [[‘Tim’, 98], [‘Tom’, 80], [‘Mike’, 50], [‘Jason’, 25]]
Example Output =
Whilst iterating over the whole collection you should do two things. Firstly you print out the names of everyone who got less than 70, and secondly you should add up the scores of all the people who got more than 70 and at the same time you increment a value
That's roughly how I personally think it should work. Mind you, I haven't coded in yonks so I could be wrong
for(int i = 0; i < collection amount; i++)
if(userScore[i] < 70)
totalAmount += userScore[i];
System.out.println("Average of those who scored higher than 70 is: " + (totalAmount/averageCount * 100));
As for the two dimensional array, I'm sure you can figure that part out, it's simple enough to extract the correct value