3.15. Mixed Up Code Practice

Try to solve each of the following. Click the Check Me button to check each solution. You will be told if your solution is too short, has a block in the wrong order, or you are using the wrong block. Some of the problems have an extra block that isn’t needed in the correct solution. Try to solve these on your phone or other mobile device!

        3-15-1: 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; --- double totalCost = price * 2; --- double pricePerShirt = totalCost / 3; --- System.out.println(pricePerShirt);
        3-15-2: 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 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; --- double tip = bill * 0.20; --- double total = bill + tip; --- int numPeople = 3; double perPersonCost = total / numPeople; --- print(perPersonCost); --- print(perpersoncost); #distractor
        3-15-3: The main method in the following class should return a random number from 1 to 50. 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 { --- public static void main(String[] args) { --- int num = Math.random() * 50 + 1; --- System.out.println(num); --- } // end main method --- } // end of class --- int num = Math.random() * 50; #distractor
        3-15-4: The main method in the following class should return the number of seconds in 5 days. 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 { --- public static void main(String[] args) { --- int sInMin = 60; int mInHour = 60; int hInDay = 24; --- int sInDay = sInMin * mInHour * hInDay; --- int total = sInDay * 5; --- System.out.println(total); --- } // end main method --- } // end class --- public Class Test1 { #distractor
        3-15-5: 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 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 { --- public static void main(String[] args) { --- double weeklyRate = 50; double goal = 500; --- double numWeeks = goal / weeklyRate; --- double numMonths = numWeeks / 4; --- System.out.println(numMonths); --- } // end main method } // end class --- public void main(String[] args) { #distractor
        3-15-6: 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 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 { --- public static void main(String[] args) --- { --- int miles = 200; double price = 2.20; int mpg = 42; --- double numGalls = miles / mpg; --- double cost = numGalls * price; --- System.out.println(totalCost); --- } --- } --- System.println(totalCost); #distractor
        3-15-7: 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 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 { --- public static void main(String[] args) --- { --- int mpg = 26; int tankHolds = 15; --- double numGalls = tankHolds / 2; --- double miles = numGalls * mpg; --- System.out.println(miles); --- } --- } --- public static main(String[] args) #distractor
        3-15-8: 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 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 { --- public static void main(String[] args) --- { --- double cost = 0.6; double money = 3.5; --- int numWings = cost / money; --- System.out.println(numWings); --- } --- } --- int cost = 0.6; int money = 3.5; #distractor
        3-15-9: 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 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 { --- public static void main(String[] args) --- { --- double price = 52.99; double discount = 0.6; --- double savings = price * discount; --- double finalPrice = price - savings; --- System.out.println(finalPrice); --- } --- } --- int price = 52.99; int discount = 0.6; #distractor
        3-15-10: 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 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 { --- public static void main(String[] args) --- { --- double price = 39.99; --- double priceForTwo = price * 2; --- double itemPrice = priceForTwo / 3; --- System.out.println(itemPrice); --- } --- } --- double priceForTwo = price * 2 #distractor
Next Section - 4. Strings