# 1.10. Coding Practice¶

The following code should print “Mary’s favorite color is blue”. However, the code has errors. Fix the code so that it compiles and runs correctly.

Line 5 is missing a starting ". Line 6 is missing a ending ;. Line 7 has Name when it should be name. Remember that variable names start with a lowercase letter.

This is the answer to the previous question.

The following code should print “Gabby’s favorite sport is soccer”. However, the code has errors. Fix the code so that it compiles and runs correctly.

Line 5 is missing a =. Line 6 is missing the closing ". Line 7 has Name when it should be name. Remember that a variable name starts with a lowercase letter. Line 8 is missing an ending +.

The following code should print Your name is Carly and your favorite color is red. Finish the code so that it prints the output correctly using the variables provided.

Add the required strings using the + operator and be sure to include spaces as needed.

This is the answer to the previous question.

Finish the code below so that it prints Your name is Justin and your age is 16 using the variables provided.

Use the + operator to append the strings. Be sure to include spaces as needed.

Write the code to print Julian's favorite color is green.  His favorite food is pizza. using the variables provided.

Add the strings together using +. Don’t forget to include spaces and periods at the end of the sentences.

This is the answer to the previous question.

Finish the code below to print your favorite animal and food.

Use + to add strings together. Add spaces as needed and periods.

This is the answer to the previous question.

Finish the code below to print your favorite movie and book.

Add the strings together using +. Don’t forget to include spaces and periods at the end of the sentences.

The following code should calculate the cost of a trip that is 300 miles if gas is $2.50 a gallon and your car gets 30 miles per gallon. However, the code has syntax errors, like missing semicolons, wrong case on names, or unmatched " or (. Fix the code so that it compiles and runs correctly. Line 5 is missing a semicolon. Line 6 has Double instead of double. Remember that the primitive types all start with a lowercase letter. Line 8 has tripmiles instead of tripMiles. Remember that you should uppercase the first letter of each new word to make the variable name easier to read (use camel case). This is the answer for the previous question. Show Comments The following code should calculate the body mass index (BMI) for someone who is 5 feet tall and weighs 110 pounds. However, the code has syntax errors, like missing semicolons, wrong case on names, or unmatched " or (. Fix the code so that it compiles and runs correctly. Line 5 has Height instead of height. Remember that variable names should start with a lowercase letter. Line 6 is missing an equal sign. Line 7 is missing a * to square the height. Line 8 is missing a semicolon at the end of the statement. This is the answer for the previous question. Show Comments The following code should calculate the number of miles that you can drive when you have$8.00 and the price of gas is 2.35 and the car gets 40 miles per gallon. However, the code has errors. Fix the code so that it compiles and runs correctly.

Line 5 is missing the type double. Line 6 is backwards. It should be double milesPerGallon = 40;. Line 8 is missing a /. Line 10 is missing a ).

This is the answer to the previous question.

The following code should calculate the cost of an item that is on clearance (70% off) when you also have a coupon for an additional 20% off the clearance price. However, the code has errors. Fix the code so that it compiles and runs correctly.

Lines 5, 6, and 7 should all be double versus int so that the decimal portion of the calculation isn’t thrown away.

This is the answer to the previous question.

The following code should calculate the number of whole days in 320893 seconds. However, the code has errors. Fix the code so that it compiles and runs correctly.

Lines 6 and 7 are both missing a /. Line 8 is missing a (. Line 9 is missing a } to close the main method.

This is the answer to the previous question.

Complete the code below to calculate and print how many months it will take to save $200 if you earn$20 a week.
Calculate how many weeks it would take to make $200. Next divide the number of weeks by 4 (roughly the number of weeks in a month). This is the answer to the previous question. Show Comments Write the code to calculate the number of miles you can drive if you have a 10 gallon gas tank and are down to a quarter of a tank of gas and your car gets 32 miles per gallon. First calculate the number of gallons you have left and then multiply that by the miles per gallon to get the number of miles you can still drive. This is the answer to the previous question. Show Comments Write the code to calculate the number of seconds in 3 days. Remember that there are 60 seconds in a minute and 60 minutes in an hour and 24 hours in a day. First compute the number of seconds in 1 day and then multiple that by 3 days. This is the answer to the previous question. Show Comments Write the code to print the number of chicken wings you can buy if you have$4.50 and they cost \$0.75 each. Remember that you can’t buy part of a wing.