Please send questions to st10@humboldt.edu .

CIS 130 - Week 9 Lecture
10-19-05
Miscellaneous "white board" projections

REVISE the design recipe... for conditionals!!

* still going to come up with a Contract...

* still going to come up with a Header...

* still going to come up with a Purpose Statement...

---> you realize you need the new step:
     Data analysis and data definition

* ...so that you can know the "categories"/"cases"/"partitions"
     that your program needs to handle;

* ...and so that you can write EXAMPLES for each of those
     cases, and for each BOUNDARY between those cases;

* so, now we're at the body.

  Do you see that you can now write the "skeleton" for
  an if or if-else or if-else-if-else involved?

  blah header(blah p1, blah p2)
  {
      if (p1 < p2)
      {
          return 13;
      }
      else if (p1 > 5)
      {
          return 14;
      }
      else if (p2 > 100)
      {
          return 15;
      }
      else
      {
          return 16;
      }
  }

Let's say that a bank pays 3% on amounts over 10,000
and they pay 2% on amounts over 5000 and less than or equal 10,000,
and pay NO interest on amounts less than or equal to 5000.

I want a function (say I'm a blank clerk) that tells me the interest
rate for a customer who wants to deposit a certain amount 
and wants to know what interest they'll get.

// Contract: interest_rate: double -> double 
// Purpose:  to calculate and return the interest rate on a
//           deposit of amount <deposit>
// Examples: interest_rate(5000) == 0.0
//           interest_rate(500) == 0.0
//           interest_rate(6000) == 0.02
//           interest_rate(10000) == 0.02
//           interest_rate(10001) == 0.03

what are my cases?
if <= 5000, interest rate should be 0
if > 5000 and <= 10000, interest rate should be 0.02
if > 10000, interest rate should be .03

double interest_rate (double deposit)
{
    const double LOWEST_RATE_LIMIT = 5000;
    const double HIGHEST_RATE_LIMIT = 10000;

    if (deposit <= LOWEST_RATE_LIMIT)
    {
        return 0.0;
    }
    else if (deposit <= HIGHEST_RATE_LIMIT)
    {
        return .02;
    }
    else 
    {
        return .03;
    }

}