Verityprep
Question Bank · Unit 2

AP® Computer Science A Selection and Iteration Practice Questions

Work through AP Computer Science A practice 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 171–180 of 357
  1. 171
  2. 172
  3. 173
  4. 174
  5. 175
  6. 176
  7. 177
  8. 178
  9. 179
  10. 180

Question 171

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 172

Multiple choice Boolean Expressions
Consider the following code. int x = 4; int y = 1; while…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 173

Multiple choice Boolean Expressions
public static String classify(int score) { String result = ""; if (score >= 90) result = "A"; if…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 174

Multiple choice Boolean Expressions
public static boolean check(int num) { return num > 0 && num % 2…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 175

Multiple choice Boolean Expressions
public static String evaluate(int temperature, boolean isRaining) { String result; if (temperature > 30 && !isRaining) { result = "beach"; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 176

Multiple choice Boolean Expressions
Consider the following boolean expression: !(x >…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 177

Multiple choice Boolean Expressions
public static boolean isSpecial(int num) { return num…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 178

Multiple choice Boolean Expressions
public static int findMax(int num1, int num2, int num3) { int max = num1; if (num2 > num1) max = num2; if (num3 >…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 179

Multiple choice Boolean Expressions
What is printed?
int x = 4, y = 10, z = 4;
boolean a = !(x > y) && !(z == x);
boolean b = (x < y) || (z > x);
boolean c = !(x == z || y < x);
System.out.println(a + " " + b + " " + c);
Pick an answer, then check it. The solution opens in a window.

Question 180

Multiple choice Boolean Expressions
What is printed?
int x = 8;
boolean c1 = (x > 5 && x < 8);
boolean c2 = !(x >= 10) || x == 8;
boolean c3 = (x < 0 || x > 12) && x != 8;
System.out.println(c1 + " " + c2 + " " + c3);
Pick an answer, then check it. The solution opens in a window.
Question 171 of 357
Page 18 of 36