Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

If this is the first time you have ever done programming, you must work with a p

ID: 3555503 • Letter: I

Question

If this is the first time you have ever done programming, you must work with a partner. In that case, when you're done, each person should turn in a copy of the work to model. If you've programmed before AND feel confident, you may do the lab solo. Otherwise work with a partner. The purpose of tins exercise is for you to practice using if/else conditional statements in a program and to get more practice creating interactive programs that use methods with parameters and return types. This exercise will also be good practice in preparation for the midterm exam. This week we looked at two problems: 'Moving Expenses' and 'Dean's List'. You and your partner should turn one of these exercises into a complete running program. So, either create MovingExpenses.java or DeansList.Java. For example, SmithJonesMovingExpenses.java. Each problem requires two inputs form the user and each problem generates four possible outputs. Details about each problem can be found on model. Your program should have at least 3 methods in addition to the main method. Two of these methods will be used to prompt the user for input(s) and return value(s) back to main. Another method, which should accept parameter(s) passed from main, will display the output of the program. You may include additional methods if you wish. Add a comment to the top of your program that includes your name and your partner's name. You are not required to provide any other commenting in this lab exercise. Test your program with various values to test that is correctly handles each possible case. Then each student should turn it in electronically to the course web site using the 'Lab 4 submission' link. Keep a copy of the code when you are done. You could use a thumb drive to transfer the file or email it from one partner to the other. Moving Expenses When you hire a mover to move your belongs from on house to another, the amount charged depends on how far the houses are away from each other and whether you want insurance. Under 40 miles is 200; 40 or more miles is 300. Insurance is 50 for trips less than 40 miles, and 100 for trips of 40 or more miles. In the partially completed calculated Cost method below, construct a nested if statement to calculate the total cost. Select the correct statement from each pair. For example, choose one of A or B, one from C or D, etc. The four statements you choose are in the correct order. Use the grid below to place the statements with the proper indentation.

Explanation / Answer

Should be A, D, F, H

because you are using nested if statements. You want to create one layer of an if statement to deal with one variable, and the next layer for the second. Your first layer of if statements will depend on distance, and the second will depend on insurance. Because you know that they are in order, you can see that A and B will correspond to the first layer, C and D will correspond to the second layer, then E and F will correspond to the second part of the first layer because you are done dealing with the first case. And then G and H will correspond to the second part of the second layer. If you look at E and F, you can see that no matter what, they will be setting the initial cost to 300, meaning that the distance must be at least 40 miles. Since the second part of the first layer is dealing with a distance of more than 40 miles, you know that the only choice left for the first part of the first layer (choosing between A and B) is that it must be less than 40 miles. Then you choose C and D accordingly. If you have less than 40 miles and you want insurance, it will be an additional 50, so you choose D because it matches your criteria. Then we know that the next part (E and F) deal with distance, not insurance, so we know to choose F. The next part is the same as before. You are traveling more than 40 miles and you want insurance. So the price will be +100, so you should choose H because it fits the criteria. Hope this was helpful