Skip to content

Commit

Permalink
Merge pull request bhoffman0#220 from amy21206/master
Browse files Browse the repository at this point in the history
Adding experiment at the end of Unit 3 - Using most common solution P…
  • Loading branch information
barbarer authored Nov 20, 2024
2 parents 1ce6f4c + c421047 commit d59e5ea
Show file tree
Hide file tree
Showing 8 changed files with 808 additions and 0 deletions.
1 change: 1 addition & 0 deletions _sources/Unit3-If-Statements/toctree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ AP CSA Exam Weighting: 15-17.5%
Exercises.rst
magpieindex.rst
frq-game-score.rst
topic-3-13-more-practice-experiment.rst
topic-3-13-more-practice-coding.rst


150 changes: 150 additions & 0 deletions _sources/Unit3-If-Statements/topic-3-13-experiment-posttest.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
.. qnum::
:prefix: exp-4-
:start: 1

Posttest
==============================

.. poll:: most-common-posttest-park
:option_1: A
:option_2: B
:option_3: C
:option_4: D
:results: instructor

<b>Theme Park Discount</b>
<br>
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:
<ul>
<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>
<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>
<li>If neither condition is met, and the person is between 13 and 19 years old (inclusive), they get a 5% discount.</li>
<li>Otherwise, there is no discount.</li>
</ul>
Select the correct code for this problem.
<b>Only the highlighted lines are different in each option.</b>
<br>

<img src="https://i.postimg.cc/bYWnKSpz/posttest-theme1.png" width="1000">

<img src="https://i.postimg.cc/XY0CvMrm/posttest-theme2.png" width="1000">



.. poll:: most-common-posttest-unlucky
:option_1: A
:option_2: B
:option_3: C
:option_4: D
:results: instructor

<b>Unlucky Number</b>
<br>
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:
<ul>
<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>
<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>
<li>If the month is odd and the minute is greater than 20, the unlucky number is the minute minus the month.</li>
<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>
</ul>
Select the correct code for this problem.
<b>Only the highlighted lines are different in each option.</b>

<br>
<img src="https://i.postimg.cc/dVmTkWd1/posttest-unlucky-1.png" width="1000">

<img src="https://i.postimg.cc/pXjjxVLK/posttest-unlucky-2.png" width="1000">

.. activecode:: most-common-posttest-work
:language: java
:autograde: unittest
:nocodelens:

.. raw:: html

<b> Working Overtime </b>


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).

.. table::
:name: work-table
:class: longtable
:align: left
:width: 80%

+----------------------------------------------------+-----------------+
| Example Input | Expected Output |
+====================================================+=================+
| ``needOvertime(4, 3)`` | ``0`` |
+----------------------------------------------------+-----------------+
| ``needOvertime(4, 18)`` | ``2`` |
+----------------------------------------------------+-----------------+
| ``needOvertime(6, 15)`` | ``1`` |
+----------------------------------------------------+-----------------+

~~~~
public class OvertimeDecision
{
public static int needOvertime(int yourWorkload, int partnerWorkload)
{
// Your Code Here //
}

public static void main(String[] args)
{
System.out.println(needOvertime(4, 3)); // Output: 0

System.out.println(needOvertime(4, 18)); // Output: 2

System.out.println(needOvertime(6, 15)); // Output: 1

}
}

====
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.IOException;
import java.util.Arrays;

public class RunestoneTests extends CodeTestHelper {
public RunestoneTests() {
super();
}

@Test
public void testValue1() throws IOException {
OvertimeDecision c = new OvertimeDecision();
assertTrue(getResults(0, c.needOvertime(4, 3), "needOvertime(4, 3)"));
}

@Test
public void testValue2() throws IOException {
OvertimeDecision c = new OvertimeDecision();
assertTrue(getResults(2, c.needOvertime(4, 18), "needOvertime(4, 18)"));
}

@Test
public void testValue3() throws IOException {
OvertimeDecision c = new OvertimeDecision();
assertTrue(getResults(1, c.needOvertime(6, 15), "needOvertime(6, 15)"));
}

@Test
public void testValue4() throws IOException {
OvertimeDecision c = new OvertimeDecision();
assertTrue(getResults(1, c.needOvertime(10, 15), "Hidden test"));
}

@Test
public void testValue5() throws IOException {
OvertimeDecision c = new OvertimeDecision();
assertTrue(getResults(2, c.needOvertime(18, 3), "Hidden test"));
}
}


148 changes: 148 additions & 0 deletions _sources/Unit3-If-Statements/topic-3-13-experiment-practice-P-lib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
Practice Problems (Mixed Code)
==============================

.. parsonsprob:: most-common-practice-alarmclock-mixed
:numbered: left
:adaptive:
:noindent:


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"``.

.. table::
:name: alarmClock-table
:class: longtable
:align: left
:width: 80%

+----------------------------------------------------+-----------------+
| Example Input | Expected Output |
+====================================================+=================+
| ``alarmClock(1, false)`` | ``7:00`` |
+----------------------------------------------------+-----------------+
| ``alarmClock(5, false)`` | ``7:00`` |
+----------------------------------------------------+-----------------+
| ``alarmClock(0, false)`` | ``10:00`` |
+----------------------------------------------------+-----------------+

-----
public class VacayAlarmClock {
public static String alarmClock(int day, boolean vacation) {
=====
if (day >= 1 && day <= 5 && (vacation == false)){
=====
return "7:00";
=====
} else if ((day == 0 || day == 6 && (vacation == false)) || (day >= 1 && day <= 5 && (vacation == true))){
=====
return "10:00";
=====
} else {
=====
return "off";
=====
}
}
}


.. parsonsprob:: most-common-practice-datefashion-mixed
:numbered: left
:adaptive:
:noindent:

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).

.. table::
:name: datFashion-table
:class: longtable
:align: left
:width: 80%

+----------------------------------------------------+-----------------+
| Example Input | Expected Output |
+====================================================+=================+
| ``dateFashion(5, 10)`` | ``2`` |
+----------------------------------------------------+-----------------+
| ``dateFashion(8, 2)`` | ``0`` |
+----------------------------------------------------+-----------------+
| ``dateFashion(5, 5)`` | ``1`` |
+----------------------------------------------------+-----------------+
-----
public class DateStylishness {
=====
public static int dateFashion(int you, int date) {
=====
if (you <= 2 || date <= 2) {
=====
return 0; }
=====
if (you >= 8 || date >= 8) {
=====
return 2; }
=====
return 1; }
=====
}


.. parsonsprob:: most-common-practice-frontback-mixed
:numbered: left
:grader: dag
:noindent:

Create the method ``front_back(str, start, end)`` that takes three strings and returns
a string based on the following conditions.

* If ``str`` contains ``start`` at the beginning and ``end`` at the end then return ``"s_e"``.
* If ``str`` contains ``start`` at the beginning of the string return ``"s"``.
* if ``str`` contains ``end`` at the end of the string return ``"e"``.
* Otherwise return ``"n"``.

.. table::
:name: front-back-table
:class: longtable
:align: left
:width: 80%

+----------------------------------------------------+-----------------+
| Example Input | Expected Output |
+====================================================+=================+
| ``front_back("Open at noon", "Open", "noon")`` | ``"s_e"`` |
+----------------------------------------------------+-----------------+
| ``front_back("Opening time", "Open", "noon")`` | ``"s"`` |
+----------------------------------------------------+-----------------+
| ``front_back("Afternoon", "Open", "noon")`` | ``"e"`` |
+----------------------------------------------------+-----------------+
| ``front_back("Closed", "Open", "noon")`` | ``"n"`` |
+----------------------------------------------------+-----------------+
| ``front_back("It is noon now", "open", "noon")`` | ``"n"`` |
+----------------------------------------------------+-----------------+

-----
public class FrontBack { #tag:0; depends:;
=====
public static String front_back(String str, String start, String end) { #tag:1; depends:0;
=====
Boolean beginWithStart = str.indexOf(start) == 0;
Boolean endWithEnd = str.indexOf(end) == (str.length() - end.length()); #tag:2; depends:1;
=====
if (beginWithStart && endWithEnd) { #tag:3; depends:2;
=====
return "s_e"; } #tag:4; depends:3;
=====
else if (beginWithStart && !endWithEnd) {
return "s";} #tag:5; depends:4;
=====
else if (!beginWithStart && endWithEnd) {
return "e";} #tag:6; depends:4;
=====
else { #tag:7; depends:5,6;
=====
return "n"; #tag:8; depends:7;
=====
} #tag:9; depends:8;
=====
} #tag:10; depends:9;
=====
} #tag:11; depends:10;
35 changes: 35 additions & 0 deletions _sources/Unit3-If-Statements/topic-3-13-experiment-practice-P.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. qnum::
:prefix: exp-2-
:start: 1

Practice Problems (Mixed Code Help)
==============================

.. selectquestion:: most-common-practice-alarmclock-toggle
:fromid: most-common-practice-alarmclock-written, most-common-practice-alarmclock-mixed
:toggle: lock

.. selectquestion:: most-common-practice-datefashion-toggle
:fromid: most-common-practice-datefashion-written, most-common-practice-datefashion-mixed
:toggle: lock

.. selectquestion:: most-common-practice-frontback-toggle
:fromid: most-common-practice-frontback-written, most-common-practice-frontback-mixed
:toggle: lock

.. raw:: html

<p>click on the following link to proceed to the posttest: <b><a id="next-link"><font size="+2">posttest</font></a></b></p>

.. raw:: html

<script type="text/javascript" >
window.onload = function() {
a = document.getElementById("next-link")
a.href = "topic-3-13-experiment-posttest.html"
};
</script>
Loading

0 comments on commit d59e5ea

Please sign in to comment.