CS173: Intro to Computer Science - Introduction to Iteration (3 Points)

Developed by Professor Tralie and Professor Mongan.

Exercise Goals

The goals of this exercise are:
  1. To use iteration to compute a discrete value
Modify the Driver.java file to compute compound interest using a loop to compute the overall interest rate.

Enter your Ursinus netid before clicking run. This is not your ID number or your email. For example, my netid is wmongan (non Ursinus students can simply enter their name to get this to run, but they won't get an e-mail record or any form of credit)

Netid
Clicking Run below will check your work and, if it passes, will submit your work automatically. You must be connected to the VPN for submission to be successful! You will receive a copy of your code via e-mail, so you'll know that it was submitted if you receive that e-mail! VPN access requires Multi-Factor Authentication, which sends you a code when you log into the network. Instructions on configuring these for your account can be found here.

Driver.java

public class Driver { public static void main(String[] args) { // balance = principal * totalInterestRate // totalInterestRate = totalInterestRate * compoundFactor, computed n*t times // ... where compoundFactor = (1 + (rate / n)) // ... where t = periods (years), n = compoundTimesPerPeriod (times per year), // ... and rate = annual interest rate (2% == 0.02) int principal = 1; // 1 dollar invested double interest = 1; // at 100% interest int years = 1; // for 1 year /* TODO: Change this to compound daily */ int compoundTimesPerYear = 12; // compounded monthly double compoundFactor = 1 + (interest / compoundTimesPerYear); double totalInterestRate = compoundFactor; // iterate one fewer time because we initialized the variable above, which counts as one multiplication for(/* TODO: Fill this in */) { totalInterestRate = totalInterestRate * compoundFactor; } double finalBalance = principal * totalInterestRate; System.out.println(finalBalance); System.out.println(totalInterestRate); } }
Driver.main(null);

Output

Fun With Limits

As your compoundTimesPerYear variable increases, your total balance approaches a certain famous constant: what is it?