# 1.10. Unit 1 Coding Practice¶

Update the main method to calculate and print the perimeter of a rectangle having width 7 and height 9. Add another statement to calculate and print the area of the rectangle on a separate line.

Update the main method to calculate and print the area of a triangle with base 7 and height 9. Recall the formula is 1/2bh. Your solution must contain at least one multiplication and one division. Watch out for integer division! int/int results in an int, while int/double results in a double.

R0 (pronounced R-naught) is a measure for predicting and controlling the transmission of disease. If R0 is 3, then each person that has a disease will spread it on average to 3 other people. The program below shows 4 iterations in the spread of SmallPox, which has an R0 of 3. The first person spreads to 3 people, each of whom spread to 3 people, etc. Update the program with additional print statements to show the spread after 4 iterations of HIV (R0 of 4) and Measles (R0 of 16).

In Unit 4 you will learn a better way to solve this problem using loops.

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. It is not an error for System.out.println to perform string concatenation across several lines of code, but there is a problem with one of the variables in the print statement.

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.

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.

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

Write the code to print “Julian’s favorite color is green. His favorite food is pizza.” using the variables provided. Watch out for spaces and the period at the end of each sentence.

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

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

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.

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.

Complete the code below to calculate and print how many months it will take to save $200 if you earn$20 a week. First calculate how many weeks it would take to make $200, then calculate how many months it will take assuming there are 4 weeks per month. 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. 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. 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. Divide the amount of money you have by the cost of each wing and then use casting to set the result to an int since you can’t buy a part of a wing.