|
| 1 | +.. qnum:: |
| 2 | + :prefix: exp-4- |
| 3 | + :start: 1 |
| 4 | + |
| 5 | +Posttest |
| 6 | +============================== |
| 7 | + |
| 8 | +.. poll:: most-common-posttest-park |
| 9 | + :option_1: A |
| 10 | + :option_2: B |
| 11 | + :option_3: C |
| 12 | + :option_4: D |
| 13 | + :results: instructor |
| 14 | + |
| 15 | + <b>Theme Park Discount</b> |
| 16 | + <br> |
| 17 | + 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: |
| 18 | + <ul> |
| 19 | + <li>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.</li> |
| 20 | + <li>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.</li> |
| 21 | + <li>If neither condition is met, and the person is between 13 and 19 years old (inclusive), they get a 5% discount.</li> |
| 22 | + <li>Otherwise, there is no discount.</li> |
| 23 | + </ul> |
| 24 | + Select the correct code for this problem. |
| 25 | + <b>Only the highlighted lines are different in each option.</b> |
| 26 | + <br> |
| 27 | + |
| 28 | + <img src="https://i.postimg.cc/bYWnKSpz/posttest-theme1.png" width="1000"> |
| 29 | + |
| 30 | + <img src="https://i.postimg.cc/XY0CvMrm/posttest-theme2.png" width="1000"> |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +.. poll:: most-common-posttest-unlucky |
| 35 | + :option_1: A |
| 36 | + :option_2: B |
| 37 | + :option_3: C |
| 38 | + :option_4: D |
| 39 | + :results: instructor |
| 40 | + |
| 41 | + <b>Unlucky Number</b> |
| 42 | + <br> |
| 43 | + 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: |
| 44 | + <ul> |
| 45 | + <li> If the month is even and the minute is greater than 30, the unlucky number is the sum of the month and the minute.</li> |
| 46 | + <li>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.</li> |
| 47 | + <li>If the month is odd and the minute is greater than 20, the unlucky number is the minute minus the month.</li> |
| 48 | + <li>If the month is odd and the minute is less than or equal to 20, the unlucky number is the month minus the minute.</li> |
| 49 | + </ul> |
| 50 | + Select the correct code for this problem. |
| 51 | + <b>Only the highlighted lines are different in each option.</b> |
| 52 | + |
| 53 | + <br> |
| 54 | + <img src="https://i.postimg.cc/dVmTkWd1/posttest-unlucky-1.png" width="1000"> |
| 55 | + |
| 56 | + <img src="https://i.postimg.cc/pXjjxVLK/posttest-unlucky-2.png" width="1000"> |
| 57 | + |
| 58 | +.. activecode:: most-common-posttest-work |
| 59 | + :language: java |
| 60 | + :autograde: unittest |
| 61 | + :nocodelens: |
| 62 | + |
| 63 | + .. raw:: html |
| 64 | + |
| 65 | + <b> Working Overtime </b> |
| 66 | + |
| 67 | + |
| 68 | + 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: |
| 69 | + * If either workload is 5 or less (i.e., there's little work left), return 0 (no need to work overtime); |
| 70 | + * With the exception that if eithr workload is 18 or more, return 2 (i.e., a large amount of work to complete); |
| 71 | + * Otherwise, return 1 (maybe). |
| 72 | + |
| 73 | + .. table:: |
| 74 | + :name: work-table |
| 75 | + :class: longtable |
| 76 | + :align: left |
| 77 | + :width: 80% |
| 78 | + |
| 79 | + +----------------------------------------------------+-----------------+ |
| 80 | + | Example Input | Expected Output | |
| 81 | + +====================================================+=================+ |
| 82 | + | ``needOvertime(4, 3)`` | ``0`` | |
| 83 | + +----------------------------------------------------+-----------------+ |
| 84 | + | ``needOvertime(4, 18)`` | ``2`` | |
| 85 | + +----------------------------------------------------+-----------------+ |
| 86 | + | ``needOvertime(6, 15)`` | ``1`` | |
| 87 | + +----------------------------------------------------+-----------------+ |
| 88 | + |
| 89 | + ~~~~ |
| 90 | + public class OvertimeDecision |
| 91 | + { |
| 92 | + public static int needOvertime(int yourWorkload, int partnerWorkload) |
| 93 | + { |
| 94 | + // Your Code Here // |
| 95 | + } |
| 96 | + |
| 97 | + public static void main(String[] args) |
| 98 | + { |
| 99 | + System.out.println(needOvertime(4, 3)); // Output: 0 |
| 100 | + |
| 101 | + System.out.println(needOvertime(4, 18)); // Output: 2 |
| 102 | + |
| 103 | + System.out.println(needOvertime(6, 15)); // Output: 1 |
| 104 | + |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + ==== |
| 109 | + import static org.junit.Assert.*; |
| 110 | + import org.junit.Test; |
| 111 | + import java.io.IOException; |
| 112 | + import java.util.Arrays; |
| 113 | + |
| 114 | + public class RunestoneTests extends CodeTestHelper { |
| 115 | + public RunestoneTests() { |
| 116 | + super(); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void testValue1() throws IOException { |
| 121 | + OvertimeDecision c = new OvertimeDecision(); |
| 122 | + assertTrue(getResults(0, c.needOvertime(4, 3), "needOvertime(4, 3)")); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + public void testValue2() throws IOException { |
| 127 | + OvertimeDecision c = new OvertimeDecision(); |
| 128 | + assertTrue(getResults(2, c.needOvertime(4, 18), "needOvertime(4, 18)")); |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + public void testValue3() throws IOException { |
| 133 | + OvertimeDecision c = new OvertimeDecision(); |
| 134 | + assertTrue(getResults(1, c.needOvertime(6, 15), "needOvertime(6, 15)")); |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + public void testValue4() throws IOException { |
| 139 | + OvertimeDecision c = new OvertimeDecision(); |
| 140 | + assertTrue(getResults(1, c.needOvertime(10, 15), "Hidden test")); |
| 141 | + } |
| 142 | + |
| 143 | + @Test |
| 144 | + public void testValue5() throws IOException { |
| 145 | + OvertimeDecision c = new OvertimeDecision(); |
| 146 | + assertTrue(getResults(2, c.needOvertime(18, 3), "Hidden test")); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + |
0 commit comments