TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

CompoundInterest

Problem statement, definition, constraints, and public examples.

Problem Statement

Interest that is compounded annually is calculated as follows: at the end of
each year, the amount of interest is determined based on the rate of interest
multiplied by the current principal (balance in the account). This amount is
then added to the principal. Create a class CompoundInterest that includes a
method called getInterestRate(), which takes a starting balance and an ending
balance as arguments. It will return a double representing the (constant)
annual interest rate that was used to go from the starting balance to ending
balance in 8 years, to EXACTLY two decimal places using the formatDouble method
provided. Be sure to call the this method before you return your result to
format your solution correctly. The only constraints are that the starting
balance is both greater than zero and less than the ending balance. Here is the
method signature:

// Precondition: Starting balance must be less than ending balance. Both inputs
must be in the range 0 to 10000
// Postcondition: The return value is a double (to exactly two decimal places)
that is the
// interest rate used to get from starting balance to ending balance over 8
years.
// A rate of 6.02% should return 6.02, and not .0602
public double getInterestRate(double starting, double ending);


We will check to make sure the input data is valid. Feel free to use any
references.

Definition

Class:
CompoundInterest
Method:
getInterestRate
Parameters:
double, double
Returns:
double
Method signature:
double getInterestRate(double param0, double param1)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems