Consider the following instance variables and incomplete method that will be use
ID: 638288 • Letter: C
Question
Consider the following instance variables and incomplete method that will be used for computing a final quiz score. A final quiz score is computed by adding all the quiz scores and dropping the lowest score from the total. The method calculateFinalQuizScore performs the computation and updates the variable finalQuizScore. Assume that the instance variables are properly initialized.
private int[] quizScores;
private int finalQuizScore;
public void calculateFinalQuizScore() {
int total = 0;
int least = quizScores[0];
for (int k = 0; k < quizScores.length; k++) {
total = total + quizScores[k];
if (quizScores[k] < least) {
least = quizScores[k];
} // end-if
} // end-for
/* MISSING STATEMENT */
} // end method calculateFinalQuizScore
Which of the following can be used to replace /* MISSING STATEMENT */ so that calculateFinalQuizScore will work as intended?
Question 13 options:
finalQuizScore = total + least;
finalQuizScore = total - least;
finalQuizScore.set(total + least);
finalQuizScore.set(total - least);
this.finalQuizScore = least;
finalQuizScore = total + least;
finalQuizScore = total - least;
finalQuizScore.set(total + least);
finalQuizScore.set(total - least);
this.finalQuizScore = least;
Explanation / Answer
//finalQuizScore = total - least;
private int[] quizScores;
private int finalQuizScore;
public void calculateFinalQuizScore() {
int total = 0;
int least = quizScores[0];
for (int k = 0; k < quizScores.length; k++) {
total = total + quizScores[k];
if (quizScores[k] < least) {
least = quizScores[k];
} // end-if
} // end-for
/* MISSING STATEMENT */
finalQuizScore = total - least;
} // end method calculateFinalQuizScore
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.