Skip to main content

Question 1: Methods and Control Structures

Average with the lowest score dropped, and name formatting

  • Units 1 and 2
  • 7 points
  • About 25 minutes

You write two methods, or a constructor and a method, of a class you're given. Part A needs loops and/or if statements plus calls to the class's own methods; Part B needs String methods. New since the course was revised for 2025–26 (first tested in May 2026): it's worth 7 points instead of 9, and points are no longer taken off as penalties. On the exam: Question 1 of 4, 7 points (Part A 4 points, Part B 3 points). Section II has 4 free-response questions in 90 minutes (45% of the score), all assessing Practice 2 (Develop Code). The exam is fully digital in Bluebook: you type your Java, and the Java Quick Reference is provided. No calculator. Suggested time is our split of the 90 minutes by points; College Board gives no per-question timing.

The question and its sources

A teacher's gradebook stores one student's quiz scores and drops the lowest one when it works out the average. You will write two methods of the Gradebook class.

The Gradebook class

Java
public class Gradebook
{
    /**
     * Returns the number of quiz scores.
     * Postcondition: the value returned is at least 2
     */
    public int getCount()
    { /* implementation not shown */ }
 
    /**
     * Returns quiz score i, a whole number from 0 to 100.
     * Precondition: 0 <= i < getCount()
     */
    public int getScore(int i)
    { /* implementation not shown */ }
 
    /** Described in part (a) */
    public double adjustedAverage()
    { /* to be implemented in part (a) */ }
 
    /** Described in part (b) */
    public static String formatName(String fullName)
    { /* to be implemented in part (b) */ }
 
    // There may be instance variables, constructors, and methods that are not shown.
}

Examples for part (a)

Scores, in orderValue returned by adjustedAverage()Why
80, 92, 75, 8886.666… (that is, 260 / 3.0)75 is dropped; (80 + 92 + 88) / 3
60, 60, 9075.0Only one 60 is dropped; (60 + 90) / 2
100, 99100.099 is dropped

Source: Hypothetical example

Suggested time: 25 minutes

Your answers are saved in this browser as you type.

Something wrong with this question?

What's wrong?

Please don't include personal details.

Part (a)

4 points

Write the method adjustedAverage, which returns the average of all the quiz scores after one copy of the lowest score is removed. The result must not be rounded or cut off: for scores 80, 92, 75 and 88 the method returns 86.666…, not 86.0. You must use getCount and getScore appropriately to receive full credit. Complete method adjustedAverage.public double adjustedAverage()

Tab indents. Press Esc, then Tab, to move on.

0 lines · 0 / 2,500 characters

Part (b)

3 points

Names are stored as last name, a comma, a space and then the first name, such as "Lovelace, Ada". Write the static method formatName, which returns the name with the first name, a single space and then the last name. For example, formatName("Lovelace, Ada") returns "Ada Lovelace" and formatName("Turing, Alan Mathison") returns "Alan Mathison Turing". Assume fullName contains exactly one ", " (a comma followed by a space), with at least one character before it and after it. Complete method formatName.public static String formatName(String fullName)

Tab indents. Press Esc, then Tab, to move on.

0 lines · 0 / 2,500 characters

Checking scoring…

Scoring it yourself shows you the rubric, examples and a model answer. Try writing your answer first.