Skip to content

Commit c421047

Browse files
committed
Adding experiment at the end of Unit 3 - Using most common solution Parsons as scaffolding
1 parent 1ce6f4c commit c421047

8 files changed

Lines changed: 808 additions & 0 deletions

_sources/Unit3-If-Statements/toctree.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ AP CSA Exam Weighting: 15-17.5%
2727
Exercises.rst
2828
magpieindex.rst
2929
frq-game-score.rst
30+
topic-3-13-more-practice-experiment.rst
3031
topic-3-13-more-practice-coding.rst
3132

3233

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
Practice Problems (Mixed Code)
2+
==============================
3+
4+
.. parsonsprob:: most-common-practice-alarmclock-mixed
5+
:numbered: left
6+
:adaptive:
7+
:noindent:
8+
9+
10+
Given a ``day`` of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a ``boolean`` indicating if we are on ``vacation``, return a string of the form ``"7:00"`` indicating when the alarm clock should ring. Weekdays, the alarm should be ``"7:00"`` and on the weekend it should be ``"10:00"``. Unless we are on vacation -- then on weekdays it should be ``"10:00"`` and weekends it should be ``"off"``.
11+
12+
.. table::
13+
:name: alarmClock-table
14+
:class: longtable
15+
:align: left
16+
:width: 80%
17+
18+
+----------------------------------------------------+-----------------+
19+
| Example Input | Expected Output |
20+
+====================================================+=================+
21+
| ``alarmClock(1, false)`` | ``7:00`` |
22+
+----------------------------------------------------+-----------------+
23+
| ``alarmClock(5, false)`` | ``7:00`` |
24+
+----------------------------------------------------+-----------------+
25+
| ``alarmClock(0, false)`` | ``10:00`` |
26+
+----------------------------------------------------+-----------------+
27+
28+
-----
29+
public class VacayAlarmClock {
30+
public static String alarmClock(int day, boolean vacation) {
31+
=====
32+
if (day >= 1 && day <= 5 && (vacation == false)){
33+
=====
34+
return "7:00";
35+
=====
36+
} else if ((day == 0 || day == 6 && (vacation == false)) || (day >= 1 && day <= 5 && (vacation == true))){
37+
=====
38+
return "10:00";
39+
=====
40+
} else {
41+
=====
42+
return "off";
43+
=====
44+
}
45+
}
46+
}
47+
48+
49+
.. parsonsprob:: most-common-practice-datefashion-mixed
50+
:numbered: left
51+
:adaptive:
52+
:noindent:
53+
54+
You and your date are trying to get a table at a restaurant. The parameter ``you`` is the stylishness of your clothes, in the range 0..10, and ``date`` is the stylishness of your date's clothes. The result getting the table is encoded as an int value with 0=no, 1=maybe, 2=yes. If either of you is very stylish, 8 or more, then the result is ``2`` (yes). With the exception that if either of you has style of 2 or less, then the result is ``0`` (no). Otherwise the result is ``1`` (maybe).
55+
56+
.. table::
57+
:name: datFashion-table
58+
:class: longtable
59+
:align: left
60+
:width: 80%
61+
62+
+----------------------------------------------------+-----------------+
63+
| Example Input | Expected Output |
64+
+====================================================+=================+
65+
| ``dateFashion(5, 10)`` | ``2`` |
66+
+----------------------------------------------------+-----------------+
67+
| ``dateFashion(8, 2)`` | ``0`` |
68+
+----------------------------------------------------+-----------------+
69+
| ``dateFashion(5, 5)`` | ``1`` |
70+
+----------------------------------------------------+-----------------+
71+
-----
72+
public class DateStylishness {
73+
=====
74+
public static int dateFashion(int you, int date) {
75+
=====
76+
if (you <= 2 || date <= 2) {
77+
=====
78+
return 0; }
79+
=====
80+
if (you >= 8 || date >= 8) {
81+
=====
82+
return 2; }
83+
=====
84+
return 1; }
85+
=====
86+
}
87+
88+
89+
.. parsonsprob:: most-common-practice-frontback-mixed
90+
:numbered: left
91+
:grader: dag
92+
:noindent:
93+
94+
Create the method ``front_back(str, start, end)`` that takes three strings and returns
95+
a string based on the following conditions.
96+
97+
* If ``str`` contains ``start`` at the beginning and ``end`` at the end then return ``"s_e"``.
98+
* If ``str`` contains ``start`` at the beginning of the string return ``"s"``.
99+
* if ``str`` contains ``end`` at the end of the string return ``"e"``.
100+
* Otherwise return ``"n"``.
101+
102+
.. table::
103+
:name: front-back-table
104+
:class: longtable
105+
:align: left
106+
:width: 80%
107+
108+
+----------------------------------------------------+-----------------+
109+
| Example Input | Expected Output |
110+
+====================================================+=================+
111+
| ``front_back("Open at noon", "Open", "noon")`` | ``"s_e"`` |
112+
+----------------------------------------------------+-----------------+
113+
| ``front_back("Opening time", "Open", "noon")`` | ``"s"`` |
114+
+----------------------------------------------------+-----------------+
115+
| ``front_back("Afternoon", "Open", "noon")`` | ``"e"`` |
116+
+----------------------------------------------------+-----------------+
117+
| ``front_back("Closed", "Open", "noon")`` | ``"n"`` |
118+
+----------------------------------------------------+-----------------+
119+
| ``front_back("It is noon now", "open", "noon")`` | ``"n"`` |
120+
+----------------------------------------------------+-----------------+
121+
122+
-----
123+
public class FrontBack { #tag:0; depends:;
124+
=====
125+
public static String front_back(String str, String start, String end) { #tag:1; depends:0;
126+
=====
127+
Boolean beginWithStart = str.indexOf(start) == 0;
128+
Boolean endWithEnd = str.indexOf(end) == (str.length() - end.length()); #tag:2; depends:1;
129+
=====
130+
if (beginWithStart && endWithEnd) { #tag:3; depends:2;
131+
=====
132+
return "s_e"; } #tag:4; depends:3;
133+
=====
134+
else if (beginWithStart && !endWithEnd) {
135+
return "s";} #tag:5; depends:4;
136+
=====
137+
else if (!beginWithStart && endWithEnd) {
138+
return "e";} #tag:6; depends:4;
139+
=====
140+
else { #tag:7; depends:5,6;
141+
=====
142+
return "n"; #tag:8; depends:7;
143+
=====
144+
} #tag:9; depends:8;
145+
=====
146+
} #tag:10; depends:9;
147+
=====
148+
} #tag:11; depends:10;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. qnum::
2+
:prefix: exp-2-
3+
:start: 1
4+
5+
Practice Problems (Mixed Code Help)
6+
==============================
7+
8+
.. selectquestion:: most-common-practice-alarmclock-toggle
9+
:fromid: most-common-practice-alarmclock-written, most-common-practice-alarmclock-mixed
10+
:toggle: lock
11+
12+
.. selectquestion:: most-common-practice-datefashion-toggle
13+
:fromid: most-common-practice-datefashion-written, most-common-practice-datefashion-mixed
14+
:toggle: lock
15+
16+
.. selectquestion:: most-common-practice-frontback-toggle
17+
:fromid: most-common-practice-frontback-written, most-common-practice-frontback-mixed
18+
:toggle: lock
19+
20+
.. raw:: html
21+
22+
<p>click on the following link to proceed to the posttest: <b><a id="next-link"><font size="+2">posttest</font></a></b></p>
23+
24+
.. raw:: html
25+
26+
<script type="text/javascript" >
27+
28+
window.onload = function() {
29+
30+
a = document.getElementById("next-link")
31+
a.href = "topic-3-13-experiment-posttest.html"
32+
33+
};
34+
35+
</script>

0 commit comments

Comments
 (0)