3.15.3. Posttest

    Theme Park Discount
    A theme park offers discounts on ticket prices based on age and the number of visits per month. The parameter age is the person's age in years, and visitsPerMonth is the average number of visits per month. The result is the discount percentage encoded as an int. The conditions are:
    • If the person is 13 years old or younger and visits the theme park 3 or more times per month, they get a 20% discount.
    • If the person is older than 13 years old and visits the theme park 5 or more times per month, they get a 10% discount.
    • If neither condition is met, and the person is between 13 and 19 years old (inclusive), they get a 5% discount.
    • Otherwise, there is no discount.
    Select the correct code for this problem. Only the highlighted lines are different in each option.
  • 1. A
  • 2. B
  • 3. C
  • 4. D
    Unlucky Number
    A local fortune teller claims that a person's unlucky number is determined based on the month and minute of their birth. The parameters are month and minute. The month is the month of birth (from 1 to 12), and the minute is the minute of birth (from 0 to 59). According to the fortune teller, the unlucky number is calculated as follows:
    • If the month is even and the minute is greater than 30, the unlucky number is the sum of the month and the minute.
    • If the month is even and the minute is less than or equal to 30, the unlucky number is the product of the month and the minute.
    • If the month is odd and the minute is greater than 20, the unlucky number is the minute minus the month.
    • If the month is odd and the minute is less than or equal to 20, the unlucky number is the month minus the minute.
    Select the correct code for this problem. Only the highlighted lines are different in each option.
  • 1. A
  • 2. B
  • 3. C
  • 4. D
Working Overtime
You and your project partner are deciding whether to work overtime based on your remaining workload. The parameter yourWorkload represents how much work you have left, and partnerWorkload represents how much work your project partner has left, both in the range from 0 to 20. The result is an int value indicating whether you both should work overtime. Return:
  • If either workload is 5 or less (i.e., there’s little work left), return 0 (no need to work overtime);

  • With the exception that if eithr workload is 18 or more, return 2 (i.e., a large amount of work to complete);

  • Otherwise, return 1 (maybe).

Example Input

Expected Output

needOvertime(4, 3)

0

needOvertime(4, 18)

2

needOvertime(6, 15)

1

You have attempted of activities on this page