Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring

Saint Louis University

Computer Science 1300/5001
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2019

Computer Science Department

Programming Assignment 04

Interest Calculator

Due: 11:59pm, Monday, 28 October 2019


Contents:


Collaboration Policy

For this assignment, you are allowed to work with one other student if you wish (in fact, we suggest that you do so). If any student wishes to have a partner but has not been able to locate one, please let the instructor know so that we can match up partners.

Please make sure you adhere to the policies on academic integrity in this regard.


Overview

The interest calculator is an interactive program which prompts the user for an interest rate and a principal, then calculates and prints the balance that would be after one year. For this project, we will provide an implementation of the high-level logic, but our implementation depends on many functions that you will have to implement.

This project differs from earlier projects in that there is an increased focus on error checking. For past projects, we have allowed you to assume that all user input is valid. For this project, you must gracefully handle any input entered by the user.


Example Session

This interest calculator will ask you to select an interest rate,
followed by a principal value.  It will then calculate and display
the principal, interest rate, and balance after one year.  You will
then be invited to execute the process again or terminate.

Please select an interest rate:
A) 3%
B) 5%
C) 7%
D) 10%
Enter A-D: 5
That is not a valid selection.

Please select an interest rate:
A) 3%
B) 5%
C) 7%
D) 10%
Enter A-D: B

Enter the principal (limit 700000): $100

Initial Principal   Interest Rate   End of Year Balance
=======================================================
$100.00             0.05            $105.00

Another Computation [y/n]? y

Please select an interest rate:
A) 1%
B) 5%
C) 8%
D) 10%
E) 14%
F) 19%
Enter A-F: H
That is not a valid selection.

Please select an interest rate:
A) 1%
B) 5%
C) 8%
D) 10%
E) 14%
F) 19%
Enter A-F: D

Enter the principal (limit 600000): zero
Please enter a number

Enter the principal (limit 600000): -0.50
You must enter a positive amount.

Enter the principal (limit 600000): $600000.01
The principal can be at most 600000.

Enter the principal (limit 600000): $2500.925
The principal must be specified in dollars and cents.

Enter the principal (limit 600000): 600000

Initial Principal   Interest Rate   End of Year Balance
=======================================================
$600000.00          0.10            $660000.00

Another Computation [y/n]? n

Quitting program. Bye.

Requirements

We are providing a function interestDriver.py, but that function attempts to import each of the following functions from a file named interestStudent.py. This program is to use functions and do complete error checking and recovery. However, the only error-checking you are responsible for is gracefully managing the user interactions.  You do not need to validate the parameters sent to your function; you may assume that my driver will send appropriate parameters in accordance with the following expectations.

Please note the following requirements:

  1. Create a function greeting() that is responsible for displaying the initial text.

  2. Create a function getRate(choices) that manages the user interaction for selecting an interest rate from among a nonempty list of integer percentages. It should return the chosen integer rate as a floating point value. That is, if the chosen rate is 8%, this function should return value 0.08. The user interaction should behave as follows:

    1. The percentage choices should be labeled with letters A, B, C, and so on.
    2. The user should select a choice by indicating the appropriate alphabetic label (e.g., B).
    3. Any other user response must be rejected:
      1. Print a polite rejection message.
      2. Redisplay the menu and re-prompt for a selection.
  3. Create a function getPrincipal(limit) that collects and returns a floating point number from the user that represents the principal amount.

    1. The principal value must be strictly greater than zero and less than or equal to the indicated limit.
    2. The user may enter the value as either an integer, or a floating-point value, but if as a floating-point number, at most 2 digits may be entered after the decimal point.
    3. When entering the principal value, the user may (but need not) place a dollar sign symbol $ in front of the principal value.
    4. If any of the above validations fail then issue a polite, informative message (as shown in the example session above) and re-prompt the user.
    5. Return the principal as a floating-point value.
  4. Create a function, computeBalance(principal, rate), that calculates and returns the year-end balance given the parameters.
    Use the formula:

    balance = principal + (principal * rate)
  5. Create a function displayTable(principal, rate, balance) that displays the results as shown in the example session. Note well in the example that the first character of each displayed value must be perfectly aligned with the first character of the column header. For example in the very first example output, the "$" of the displayed $105.00 is aligned with the "E" in "End of Year Balance".

  6. Implement a function askYesNo(prompt) that accepts any line that has either 'y' or 'Y' as the first non-blank character to indicate yes, and any line that has either 'n' or 'N' as the first non-black character to indicate no; any other response is inconclusive in which case the questions should be repeated.
    For example,

    	y
    	Yes
    	yah
    	

    would all be accepted to indicate yes.

    At its conclusion, the function should return True if the user indicated yes, and False if the user indicated no.

In general, make sure that I cannot crash your program with any input I might give it. Seeing an exception is considered a crash. Don't forget to check conversions; int() and float() can raise exceptions.


Files We Provide

We will provide two files:


Submitting Your Assignment

This project must be submitted electronically using our department's git repository. More specifically, we have created a folder named program04 in your repositiory and you should place the following two files within:

See as well a discussion of the late policy for programming assignments.


Grading Standards

The assignment is worth 40 points, apportioned as follows:


Extra Credit

In addition to displaying the required end-of-year balance, display twelve monthly balances, assuming that interest is compounded monthly. Treat the indicated interest rate as an Annual Percentage Rate (APR). An effective monthly interest rate can be computed using the following formula in Python:

monthly = pow(1+annual, 1.0/12) - 1

Applying that rate monthly should result in the same end-of-year balance as in the original computation.

Display your results as follows:

Initial Principal   Interest Rate   End of Year Balance
=======================================================
$950.00             0.12            $1064.00

Month   Starting Balance    APR     Ending Balance
==================================================
Jan     $ 950.00            0.12    $ 959.01
Feb     $ 959.01            0.12    $ 968.11
Mar     $ 968.11            0.12    $ 977.30
Apr     $ 977.30            0.12    $ 986.57
May     $ 986.57            0.12    $ 995.94
Jun     $ 995.94            0.12    $1005.39
Jul     $1005.39            0.12    $1014.93
Aug     $1014.93            0.12    $1024.56
Sep     $1024.56            0.12    $1034.28
Oct     $1034.28            0.12    $1044.09
Nov     $1044.09            0.12    $1054.00
Dec     $1054.00            0.12    $1064.00

Michael Goldwasser
Last modified: Saturday, 21 December 2019