Section12.11Unit 1b Subgoal Labeled Puzzles for Toggle Code
These are copies of the Mixed Up Code Practice 1b puzzles with subgoal labels added. The Unit 1b Toggle Code Practice page uses them as the Get Help puzzles for its write code problems. Problems whose solution has fewer than two subgoals keep the original, unlabeled puzzle.
The main method in the following class should print a random number from 1 to 50. 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 button to check your solution.
public class Test1
{
---
public static void main(String[] args)
{
---
// Pick a random whole number in the range
int num = (int)(Math.random() * 50) + 1;
---
// Pick a random whole number in the range
int num = (int) Math.random() * 50 + 1; #paired
---
// Pick a random whole number in the range
int num = (int)(Math.random() * 50); #paired
---
// Pick a random whole number in the range
int num = Math.random() * 50 + 1; #paired
---
// Display the random number
System.out.println(num);
---
} // end main method
---
} // end of class
The main method in the following class should print the first 2 characters of the message followed by the last 2 characters of the message. 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 button to check your solution.
public class Test1
{
---
public static void main(String[] args)
{
---
// Store the message
String message = "I hope this works";
---
// Get the start of the message
String part1 = message.substring(0,2);
---
// Get the start of the message
String part1 = message.substring(0,1); #paired
---
// Get the end of the message
String part2 = message.substring(message.length() - 2);
---
// Get the end of the message
String part2 = message.substring(message.length() - 2, message.length() - 1); #paired
---
// Combine the start and end
String ends = part1 + part2;
---
// Combine the start and end
String ends = part1 * part2; #paired
---
// Display the combined start and end
System.out.println(ends);
---
} // end main method
---
} // end of class
The main method in the following class should print the initials in lowercase letters. 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 button to check your solution.
public class Test1
{
---
public static void main(String[] args)
{
---
// Store the names
String first = "Gerald";
String middle = "Foster";
String last= "Jones";
---
// Get the first letter of each name
String initials = first.substring(0,1) +
middle.substring(0,1) +
last.substring(0,1);
---
// Change the first letters into lowercase
String lowerInitials = initials.toLowerCase();
---
// Change the first letters into lowercase
initials.toLowerCase(); #paired
---
// Display the lowercase letters
System.out.println(lowerInitials);
---
// Display the lowercase letters
System.out.println(initials); #paired
---
} // end main method
---
} // end of class
The main method in the following class should print the message in all uppercase letters. 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 button to check your solution.
public class Test1
{
---
public static void main(String[] args)
{
---
// Store the message
String message = "Don't Pokemon and drive!";
---
// Change the message into uppercase
String upperMessage = message.toUpperCase();
---
// Change the message into uppercase
message.toUpperCase(); #paired
---
// Display the uppercase message
System.out.println(upperMessage);
---
// Display the uppercase message
System.print(upperMessage); #paired
---
// Display the uppercase message
System.out.println(message); #paired
---
} // end main method
---
} // end of class
The main method in the following class should print the first 3 letters of message in uppercase letters. 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 button to check your solution.
public class Test1
{
---
public static void main(String[] args)
{
---
// Store the message
String message = "Have a nice day!";
---
// Get the start of the message
String part = message.substring(0,3);
---
// Get the start of the message
String part = message.substring(0,4); #paired
---
// Change the start into uppercase
String upper = part.toUpperCase();
---
// Change the start into uppercase
part.toUpperCase(); #paired
---
// Display the uppercase letters
System.out.println(upper);
---
// Display the uppercase letters
System.out.println(part); #paired
---
} // end main method
---
} // end of class
The main method in the following class should print the part of the message starting with the word βniceβ. 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 button to check your solution.
public class Test1
{
---
public static void main(String[] args)
{
---
// Store the message
String message = "Have a nice day!";
---
// Find where the word starts in the message
int pos = message.indexOf("nice");
---
// Find where the word starts in the message
int pos = message.indexof("nice"); #paired
---
// Get the part of the message starting at the word
String part = message.substring(pos);
---
// Get the part of the message starting at the word
String part = message.substring(0, pos); #paired
---
// Display the part of the message
System.out.println(part);
---
} // end main method
---
} // end of class