Mrs. Marshall\'s Computer Design class has a series of pop quizzes to access the
ID: 3806460 • Letter: M
Question
Mrs. Marshall's Computer Design class has a series of pop quizzes to access the student's knowledge of the material. For a single student, a series of the quiz scores is entered followed by a trailer record of -1. The following rules apply in determining the total points allotted for quizzes: 1) Six quiz scores are added together to form the total quiz portion of the final grade. 2) If the student has taken over six quizzes, the lowest scores are not used. 3) If the student has taken under six quizzes, the lowest quiz score is 'padded in' as many times as it takes to make up a total of six quiz scores. NOTE: You may assume there will be at least one quiz score and no more than 10 scores. Sorting the array will make the solution doable. Write a method receiving the object array which prints out the array before and after sorting. Printed output should include the sum for three test runs for 2, 6 and 9 quizzes.
it is a JAVA progamming.
Explanation / Answer
private static void calculateTotalPoints(int[] scores) {
System.out.println("Array before sorting : "+Arrays.toString(scores));
Arrays.sort(scores);
System.out.println("Array after sorting : "+Arrays.toString(scores));
int sum=0;
//Less than 6 scores
// checking for 7 as the first score is always -1 in the sorted array
if( scores.length >= 7 ){
for (int i =scores.length-1; i>=scores.length-6;i--){
sum = sum + scores[i];
}
System.out.println("Total points allotted for quizzes is : "+sum);
}
else{
int count = 7-scores.length;
for (int i=1; i<scores.length; i++){
sum = sum + scores[i];
}
//padding the least score
sum = sum + count*scores[1];
System.out.println("Total points allotted for quizzes is : "+sum);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.