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.

Questions 351–360 of 740
  1. 351
  2. 352
  3. 353
  4. 354
  5. 355
  6. 356
  7. 357
  8. 358
  9. 359
  10. 360

Question 351

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 352

Multiple choice Iteration
int x = (int)(Math.random() * 10); while (x < 5) { System.out.print(x + " "); x =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 353

Multiple choice Iteration
Consider the following code. int x = (int)(Math.random() * 5); while (x > 0) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 354

Multiple choice Iteration
Consider the following code. int x = 0; while (x < 5) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 355

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 356

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 357

Multiple choice Iteration
public static int mystery(int x) { int y = 1; while (x > 1 && y <…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 358

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 359

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 360

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 351 of 740
Page 36 of 74