Skip to main content
Logo image

Section 15.1 FRQ 1A - Methods and Control - Part 1

From the 2025 Course and Exam Description:
Free-Response Question 1: Methods and Control Structures. Students will write two methods or one constructor and one method of a given class based on the provided specifications and examples. In Part A (4 points), the method or constructor will require students to write iterative or conditional statements, or both, as well as statements that call methods in the specified class. In Part B (3 points), the method or constructor will require calling String methods.
FRQ 1A requires the following skills:
  • Complete a method or a constructor
  • Call a method in the same class or from an object
  • Use if statements
  • Use a for loop or a while loop
Teacher Insights
  • You do not need to include import statements. You can assume that any standard Java class is already imported.
  • You will NEVER print. If you think you need to print, you probably need to return something.
  • You will NOT need to write a main.

Subsection 15.1.1 Return Types and Method Headers

The return type determines the type of information the method returns.
Figure 15.1.1.
Recommendation: If you have a return type, create a variable of that type, set it to the default value, and immediately return it. Then add code in the middle!!!

Subsection 15.1.2 Calling Methods

Some FRQs will give you methods that you need to call in order to get points. Sometimes they will be in the same class as your method. Sometimes, you will need to call the methods on an object.
When methods are in the same class, you just need to call the method name and pass the necessary arguments. When methods are in different classes, you use an object to call the method with dot notation and pass the necessary arguments. If the method returns a value, make sure you are storing or using the value somehow.
Example : The orderCoffee and calculateTotal methods are in the same class, so you can call them with the method name. Make sure you pass appropriate arguments.
public class CoffeeShop {
    public double orderCoffee(int quantity, double pricePerCup) {
        // Calls the calculateTotal method and stores the return value as total
        double total = calculateTotal(quantity, pricePerCup);
        return total * 1.10;
    }

    public double calculateTotal(int count, double price) {
        return count * price;
    }
}
Remember that when a method returns a value, you must store it as a variable in order to use it again!

Subsection 15.1.3 2019 FRQ - AP Calendar - Part (b)

The APCalendar class contains methods used to calculate information about a calendar. You will write one method of the class.
public class APCalendar {
    /**
     * Returns the value representing the day of the week for the first day of year, where 0 denotes
     * Sunday, 1 denotes Monday, ..., and 6 denotes Saturday.
     */
    private static int firstDayOfYear(int year) {
        /* implementation not shown */
    }

    /**
     * Returns n, where month, day, and year specify the nth day of the year. Returns 1 for January
     * 1 (month = 1, day = 1) of any year. Precondition: The date represented by month, day, year is
     * a valid date.
     */
    private static int dayOfYear(int month, int day, int year) {
        /* implementation not shown */
    }

    /**
     * Returns the value representing the day of the week for the given date (month, day, year),
     * where 0 denotes Sunday, 1 denotes Monday, ..., and 6 denotes Saturday. Precondition: The date
     * represented by month, day, year is a valid date.
     */
    public static int dayOfWeek(int month, int day, int year) {
        /* to be implemented in part (b) */
    }

    // There may be instance variables, constructors, and other methods not shown.
}
Write the static method dayOfWeek, which returns the integer value representing the day of the week for the given date (month, day, year), where 0 denotes Sunday, 1 denotes Monday, ..., and 6 denotes Saturday.
For example, 2019 began on a Tuesday, and January 5 is the fifth day of 2019. As a result, January 5, 2019, fell on a Saturday, and the method call dayOfWeek(1, 5, 2019) returns 6.
As another example, January 10 is the tenth day of 2019. As a result, January 10, 2019, fell on a Thursday, and the method call dayOfWeek(1, 10, 2019) returns 4.
In order to calculate this value, two helper methods are provided for you.
  • firstDayOfYear(year) returns the integer value representing the day of the week for the first day of year, where 0 denotes Sunday, 1 denotes Monday, ..., and 6 denotes Saturday. For example, since 2019 began on a Tuesday, firstDayOfYear(2019) returns 2.
  • dayOfYear(month, day, year) returns n, where month, day, and year specify the nth day of the year. For the first day of the year, January 1 (month = 1, day = 1), the value 1 is returned. This method accounts for whether year is a leap year. For example, dayOfYear(3, 1, 2017) returns 60, since 2017 is not a leap year, while dayOfYear(3, 1, 2016) returns 61, since 2016 is a leap year.
This table shows how the calculations would be made:
Figure 15.1.2.

Activity 15.1.1.

What is the return type of the dayOfWeek method?
  • void
  • This method definitely wants you to return something!
  • int
  • This method wants you to return a value that represents a day of the week. The best type is int.
  • double
  • This method wants you to return a value that represents a day of the week. Does that need a decimal?
  • None, it’s a constructor.
  • This method wants you to return a value that represents a day of the week. We are not constructing any objects here.

Activity 15.1.2.

The dayOfWeek method includes the parameters month, day, year. What is the correct way to call the firstDayOfYear method?
  • firstDayOfYear(int year)
  • We do not need to include the type when passing arguments to a method.
  • firstDayOfYear(2019)
  • We want to use a variable name here instead of a single value.
  • firstDayOfYear(year)
  • firstDayOfYear(year) requires one argument which should be a year
  • firstDayOfYear(month, day, year)
  • This method only requires one argument, not three.

Activity 15.1.3.

The dayOfWeek method includes the parameters month, day, year. What is the correct way to call the dayOfYear method?
  • dayOfYear(int month, int day, int year)
  • We do not need to include the type when passing arguments to a method.
  • dayOfYear(1, 5, 2019)
  • We want to use a variable name here instead of a single value.
  • dayOfYear(year)
  • dayOfYear(month, day, year) requires three arguments instead of one
  • dayOfYear(month, day, year)
  • Yes! dayOfYear(month, day, year) requires three values, and we want them to be variables.

Activity 15.1.4.

Complete the method dayOfWeek below. You must use firstDayOfYear and dayOfYear appropriately to receive full credit.
You could do this on a single line or several lines.

Subsection 15.1.4 Calling Static Methods

Some methods are static methods and should be called using the class name instead of an object.
Math methods are static methods:

Subsection 15.1.5 Calling Methods on Objects

Sometimes you need to call methods on objects. In most FRQs, these objects will already exist. We will specifically look at calling String methods later.
To call a method on an object, you use objectName.methodName(arguments).
Example : The Match class has two instance variables team1 and team2 of type Team. We can call the getScore() method that is part of Team using the name of the team object and the method name: team1.getScore() and team2.getScore().
public class Team {
    public int getScore() {
        /* Implementation not shown */
    }
}

public class Match {
    Team team1, team2;

    public int determineWinner() {
        if (team1.getScore() > team2.getScore()) return 1;
        else if (team1.getScore() < team2.getScore()) return 2;
        return 0;
    }
}

Subsection 15.1.6 2022 FRQ - Game and Level

In this simplified version of this FRQ, you will use the 3 Level objects for the 3 levels of the game and then call their getPoints() methods to calculate the score for the game.
You are given the following classes:
public class Level {
    /** Returns the number of points recorded for this level */
    public int getPoints() {
        return points;
    }
}

public class Game {
    private Level levelOne, levelTwo, levelThree;

    public int getScore() {
        /* to be implemented in this question */
    }
}
The score is calculated by adding the points from each level, but in this version, level 2 points are doubled, and level 3 points are tripled. You are to write the getScore method in Game.

Activity 15.1.5.

What is the return type of this method?
  • void
  • This method definitely wants you to return something!
  • int
  • This method wants you to return a value that represents a day of the week. The best type is int.
  • double
  • This method wants you to return a value that represents a day of the week. Does that need a decimal?
  • None, it’s a constructor.
  • This method wants you to return a value that represents a day of the week. We are not constructing any objects here.

Activity 15.1.6.

How do you call the getPoints() method for levelOne?
  • levelOne.getPoints()
  • This is the correct way to call getPoints() on a specific level.
  • getPoints(levelOne)
  • Remember that getPoints() must be called on an object and does not take any arguments.
  • Level.getPoints()
  • Remember that getPoints() is not a static method
  • Level.getPoints(levelOne)
  • Remember that getPoints() is not a static method and does not take any arguments.

Activity 15.1.7.

Complete the getScore method below. The score is calculated by adding the points from each level, but in this version, level 2 points are doubled, and level 3 points are tripled.
You have attempted of activities on this page.