CS 141 - Fall 2019

Program 1: Car Payment Calculator

Assigned: Wednesday, August 28
Due: Thursday, September 5, 2019 by 11:55pm (on Moodle)

Description

In this project, you will write a program to calculate information about a car loan. Often a car is too expensive to purchase outright, so people will obtain a loan, by which they pay off the car over a period of years.

There are a number of factors involved with a car loan. There's an initial sales price for the car, on which the buyer must pay sales tax. Often the buyer will be trading in a previous vehicle and this amount (trade-in value) is deducted from the purchase price before tax is added. Sometimes the buyer will pay some amount of money upfront, before the loan, as a down payment. This amount is deducted after tax is added. The remainder of the purchase price (the amount left over after the down payment and trade-in value is taken away) becomes the principal value of the loan (the amount that the person must borrow).

From this principal, the car buyer negotiates with a lender an interest rate for the loan and the amount of time in years over which the loan will be repaid. There is a particular formula used to calculate the monthly payment of the loan:

                 P ( r / 12 )
	   -------------------------
                               -m 
	    (1 - ( 1 + r / 12 )   )
where P = is the principal, r = the interest rate, and m = the number of monthly payments.

Here's an example. Suppose you are interested in buying a car that costs $25,000, and sales tax is 9.25%. $25,000 is the purchase price. Say you trade-in your previous car for $3000 and put down an additional $2000 as a down payment. The total taxable amount is then $22000. Multiply this by 1.0925 to determine the amount with tax, which is $24,035.00. Then subtract your down payment amount of $2000. The remainder, $22,035.00 becomes the principal for your loan. Suppose you get a 3.5% interest rate on a 5-year loan. You must make a payment every month, which means you'll make 60 payments. The payment each month will be:

        	22035 ( 0.035 / 12 )
	---------------------------------
	                         -60 
	   (1 - ( 1 + 0.035 / 12 )     )
which comes out to approximately $400.86. Note that r has been converted from a percent to a decimal.

What you need to do

Start a new Python program (in a separate window, not the Python shell). Put a comment at the top with your name and a description of what the program does. Your comment should look like the standard program header shown here. Write the program so that it does the following: If you are confused, just make your program act identically to the examples below.

Sample Interactions

What the computer displays (prints) is in regular text, what the user types is in bold, and what the program is doing behind the scenes is in italics.

Test 1

(Program begins)
Welcome to the car loan calculator.
Please enter the following to determine your monthly payment.
Purchase price of car: 25000
Sales tax rate (enter 9.25% as 9.25): 9.25
Trade-in value: 3000
Down payment amount: 2000
The principal value of your loan will be 22035.0
Number of years loan will last: 5
Interest rate of loan: 3.5
You will make 60 payments of 400.8551004195982
Over 5 years, this will be a total of 24051.306025175894
(Program ends)

Test 2

(Program begins)
Welcome to the car loan calculator.
Please enter the following to determine your monthly payment.
Purchase price of car: 15000
Sales tax rate (enter 9.25% as 9.25): 6.5
Trade-in value: 2500
Down payment amount: 1000
The principal value of your loan will be 12312.5
Number of years loan will last: 7
Interest rate of loan: 5.5
You will make 84 payments of 176.93115014527436
Over 7 years, this will be a total of 14862.216612203047
(Program ends)
Your code does not need to follow this script verbatim, but all the mentioned functionality should work as shown.

Hints

Work out some examples on paper first to determine how the math works in this problem. Decide on what variables you need, what they represent in the problem, and what their data types should be. Test your program on lots of examples and make sure the math checks out.

How to get started

  • Create a Python program named yourlastname_yourfirstname_prg1.py
  • Follow the instructions for commenting your code (ignore the section on comments before each function for this program).
  • Submit your Python file on Moodle under Program 1.
  • Requirements

    A good program will do all of the following:

  • Program file is named correctly.
  • Include the standard program header as a comment at the top of your program.
  • Ask the user for all input using clear and understandable prompts.
  • Display all information using clear and understandable messages.
  • Using appropriate variable naming conventions.
  • Code is commented appropriately, is neatly and clearly formatted, and it includes proper use of 'white space'.
  • Challenge Problems

    From time to time, I will offer "challenge problems" on assignments. These problems are designed to have little (but some) impact on your grade whether you do them or not. You should think of these problems as opportunities to work on something interesting and optional, rather than a way to raise your grade through "extra credit."

    Policy on challenge problems:

    Challenge problems for this assignment:

    Grading

    Your program will be graded on correctness (whether your calculations are correct), as well as on coding style, which refers to choices you make when writing your code, such as good use of variable names, appropriate indentation, and comments (this is not an exhaustive list).

    You will receive one bonus point for every complete day your program is turned in early, up to a maximum of five points. For instance, if your program is due on September 20 at 11:59pm, if you turn in your code on Moodle any time on September 19 from 12:00am through 11:59pm, you will receive one extra point on your project. Programs submitted on September 18 from 12:00am through 11:59pm will receive two points. This pattern continues for up to five points.