Verityprep
Question Bank · Unit 2

AP® Computer Science A Selection and Iteration FRQ

Work through AP Computer Science A free-response questions on Selection and Iteration, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Subtopic: Boolean Expressions Clear filter

Questions 31–40 of 41
  1. 31
  2. 32
  3. 33
  4. 34
  5. 35
  6. 36
  7. 37
  8. 38
  9. 39
  10. 40

Question 31

Free response Boolean Expressions
Given 3 int values, a b c, return their sum. However, if one of the values is the same as another of the values, it does not count towards the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 32

Free response Boolean Expressions
Given 3 int values, a b c, return their sum. However, if one of the values is 13 then it does not count towards the sum and values to its right do not count. So…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 33

Free response Boolean Expressions
Given 3 int values, a b c, return their sum. However, if any of the values is a teen -- in the range 13..19 inclusive -- then that value counts as 0, except 15…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 34

Free response Boolean Expressions
For this problem, we'll round an int value up to the next multiple of 10 if its rightmost digit is 5 or more, so 15 rounds up to 20. Alternately, round down to…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 35

Free response Boolean Expressions
Given three ints, a b c, return true if one of b or c is "close" (differing from a by at most 1), while the other is "far", differing from both other values by…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 36

Free response Boolean Expressions
Given 2 int values greater than 0, return whichever value is nearest to 21 without going over. Return 0 if they both go over.…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 37

Free response Boolean Expressions
Given three ints, a b c, one of them is small, one is medium and one is large. Return true if the three values are evenly spaced, so the difference between…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 38

Free response Boolean Expressions
We want make a package of goal kilos of chocolate. We have small bars (1 kilo each) and big bars (5 kilos each). Return the number of small bars to use,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 39

Free response Boolean Expressions

A regional airport uses a computerized scheduling system to manage daily flight departures. Each flight has a scheduled departure time and an actual departure time, both stored as integers in 24-hour format where the value represents hours and minutes combined. For example, 1430 represents 2:30 PM and 905 represents 9:05 AM. You will write two methods for the FlightScheduler class to help the operations team analyze the day's performance.

PART A

Write the method public int minutesBetween(int time1, int time2) that converts two times from HHMM format to total minutes since midnight and returns the absolute difference. For example, minutesBetween(1430, 900) should return 330 because \(14\times60+30 = 870\) minutes and \(9\times60+0 = 540\) minutes, and the absolute difference is 330.

public int minutesBetween(int time1, int time2) {

PART B

Write the method public int countDelays(int[] scheduled, int[] actual, int threshold) that returns the number of flights where the actual departure was more than threshold minutes after the scheduled time. You may call the minutesBetween method from Part A. A flight is only considered delayed if the actual time is later than the scheduled time and the difference exceeds the threshold.

For example, if scheduled is [800, 1200, 1500] and actual is [830, 1155, 1545] with threshold 20, the method returns 2 because the first flight (30 minutes late) and the third flight (45 minutes late) exceed the threshold.

public int countDelays(int[] scheduled, int[] actual, int threshold) {
The answer and the full solution open in a window.

Question 40

Free response Boolean Expressions
This problem involves calculating the total amount due for a restaurant bill, including tip and a possible service charge for large groups, then dividing among…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 31 of 41
Page 4 of 5