Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions CodeTestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ public CodeTestHelper(String name) {

public CodeTestHelper(String name, String input){
inContent = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));
InputStream temp = System.in;
System.setIn(inContent);

setupClass(name);

System.setIn(System.in);
System.setIn(temp);

}

Expand Down Expand Up @@ -1483,13 +1484,15 @@ public boolean containsMatch(String orig, String target) {

public String getMethodOutputWithInput(String methodName, String input) {
inContent = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));
InputStream temp = System.in;

System.setIn(inContent);

String output = getMethodOutput(methodName);

System.setIn(System.in);
System.setIn(temp);

return output;
}

}
}
4 changes: 2 additions & 2 deletions _sources/MixedFreeResponse/RandomStringChooserParsonsA.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Mixed Up Code Practice
:adaptive:
:noindent:

The mixed up code below includes the correct code for the class, a field, a constructor, and the <code>getNext</code> method. In the constructor it will create an <code>ArrayList</code> and fill it by looping through the array and adding each string to the list. In the <code>getNext</code> method, if the list length is greater than zero, it will pick a position at random in the list and remove the item from that position and return it. Otherwise, if the list is empty, it returns "NONE". The blocks have been mixed up and include extra blocks that aren't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The mixed up code below includes the correct code for the class, a field, a constructor, and the ``getNext`` method. In the constructor it will create an ``ArrayList`` and fill it by looping through the array and adding each string to the list. In the ``getNext`` method, if the list length is greater than zero, it will pick a position at random in the list and remove the item from that position and return it. Otherwise, if the list is empty, it returns "NONE". The blocks have been mixed up and include extra blocks that aren't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class RandomStringChooser
{
Expand Down Expand Up @@ -95,7 +95,7 @@ More Mixed Up Code Practice
:adaptive:
:noindent:

The mixed up code below includes the correct code for the class, a field, a constructor, and the <code>getNext</code> method. In the constructor it will create an <code>ArrayList</code> and fill it by looping through the array and adding each string to the list. In <code>getNext</code> it will return "NONE" if the length of the list is 0. Otherwise, it will calculate a random index in the list, remove the string at that index, and return it. The blocks have been mixed up and include extra blocks that aren't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The mixed up code below includes the correct code for the class, a field, a constructor, and the ``getNext`` method. In the constructor it will create an ``ArrayList`` and fill it by looping through the array and adding each string to the list. In ``getNext`` it will return "NONE" if the length of the list is 0. Otherwise, it will calculate a random index in the list, remove the string at that index, and return it. The blocks have been mixed up and include extra blocks that aren't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class RandomStringChooser
{
Expand Down
2 changes: 1 addition & 1 deletion _sources/MixedFreeResponse/RandomStringChooserParsonsB.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Assume that the ``RandomStringChooser`` class that you wrote in part (a) has bee
:adaptive:
:noindent:

The code below will copy the strings from the array to a list in the constructor using a general for loop. In ``getNext`` it will return "NONE" if the length of the list is 0. Otherwise it till calculate a random index in the list and remove and return the string at that index. The blocks have been mixed up and include extra blocks that aren't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The code below will copy the strings from the array to a list in the constructor using a general for loop. In ``getNext`` it will return "NONE" if the length of the list is 0. Otherwise it till calculate a random index in the list and remove and return the string at that index. The blocks have been mixed up and include extra blocks that aren't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public RandomLetterChooser (String str)
{
Expand Down
4 changes: 2 additions & 2 deletions _sources/Unit1-Getting-Started/topic-1-4-assignment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ In the mixed up programs below, drag the blocks to the right to put them in the
The following has the correct code that uses a third variable named "temp" to swap the
values in h and w.

The code is mixed up and contains <b>one extra block</b> which is not needed
The code is mixed up and contains **one extra block** which is not needed
in a correct solution. Drag the needed blocks from the left into the correct
order on the right, then check your solution.
You will be told if any of the blocks are in the wrong order or if you need to remove
one or more blocks.

After three incorrect attempts you will be able to use the <i>Help Me</i> button to make the problem easier.
After three incorrect attempts you will be able to use the *Help Me* button to make the problem easier.
-----
int h = 3;
int w = 5;
Expand Down
28 changes: 14 additions & 14 deletions _sources/Unit1-Getting-Started/topic-1-9-practice-mixed-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The following program segment should print Maria's first name on one line and her last name on the next line. But, the blocks have been mixed up and include an extra block that isn't needed in the solution. Drag the blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should print Maria's first name on one line and her last name on the next line. But, the blocks have been mixed up and include an extra block that isn't needed in the solution. Drag the blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
String firstName = "Maria";
String lastName = "Hernandez";
Expand All @@ -32,7 +32,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The following program segment should print the words to a famous poem. But the blocks have been mixed up. Drag the blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should print the words to a famous poem. But the blocks have been mixed up. Drag the blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
System.out.println("Roses are red");
=====
Expand All @@ -49,7 +49,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should print Marcus's name on one line and his favorite color on the next line. But, the blocks have been mixed up and include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should print Marcus's name on one line and his favorite color on the next line. But, the blocks have been mixed up and include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down Expand Up @@ -78,7 +78,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The following program segment should figure out the cost for each shirt if they are buy 2 and get the third free and they are originally $45 each. But, the blocks have been mixed up. Drag the blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should figure out the cost for each shirt if they are buy 2 and get the third free and they are originally $45 each. But, the blocks have been mixed up. Drag the blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
double price = 45;
=====
Expand All @@ -95,7 +95,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The following program segment should figure out the cost per person for a dinner including the tip. But the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should figure out the cost per person for a dinner including the tip. But the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
double bill = 89.23;
=====
Expand All @@ -118,7 +118,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should print the number of seconds in 5 days. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should print the number of seconds in 5 days. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down Expand Up @@ -149,7 +149,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should calculate the number of months it would take you to save 500 if you make 50 a week. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should calculate the number of months it would take you to save 500 if you make 50 a week. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down Expand Up @@ -179,7 +179,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should print the name on one line followed by the age on the next line. But, the blocks have been mixed up and include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should print the name on one line followed by the age on the next line. But, the blocks have been mixed up and include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down Expand Up @@ -207,7 +207,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should print the name on one line and the favorite food on the next line. But, the blocks have been mixed up and include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should print the name on one line and the favorite food on the next line. But, the blocks have been mixed up and include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down Expand Up @@ -236,7 +236,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should calculate the cost of a trip that is 200 miles when the price of gas is 2.20 and the miles per gallon is 42. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should calculate the cost of a trip that is 200 miles when the price of gas is 2.20 and the miles per gallon is 42. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down Expand Up @@ -267,7 +267,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should calculate how many miles you can go on half a tank of gas if the miles per gallon is 26 and your tank holds 15 gallons. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should calculate how many miles you can go on half a tank of gas if the miles per gallon is 26 and your tank holds 15 gallons. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down Expand Up @@ -297,7 +297,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should calculate how many chicken wings you can buy with $3.50 if the wings are $.60 each. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should calculate how many chicken wings you can buy with $3.50 if the wings are $.60 each. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down Expand Up @@ -326,7 +326,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should calculate how much you will have to pay for an item that is 60% off the original price of $52.99. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should calculate how much you will have to pay for an item that is 60% off the original price of $52.99. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down Expand Up @@ -357,7 +357,7 @@ Try to solve each of the following. Click the *Check Me* button to check each so
:adaptive:
:noindent:

The main method in the following class should calculate how much the per item costs is for shorts that are buy 2 and get the third free. The shorts are $39.99 each. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The main method in the following class should calculate how much the per item costs is for shorts that are buy 2 and get the third free. The shorts are $39.99 each. But, the blocks have been mixed up and may include an extra block that isn't needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the *Check Me* button to check your solution.
-----
public class Test1
{
Expand Down
Loading