## Class FindPrincipal

```java.lang.Object
FindPrincipal
```

`public class FindPrincipalextends java.lang.Object`

FindPrincipal.java
Solution for CS 201 HW 1 problem 2
Program to calculate the maximum principal available at a given interest rate, mortgage length, and monthly payment

Constructor Summary
`FindPrincipal()`

Method Summary
`static double` ```find(double mortgage, double interest, double years)```
Calls findBetween 0 and the upper bound
`static double` ```findBetween(double mortgage, double interest, double years, double lo, double hi)```
Finds the ideal principal using a binary search of whether the monthly payment is too high or too low
`static void` `main(java.lang.String[] args)`
Calls testFind with mortgage = 1200.00, interst = 7.00, and years = 30.0.
`static void` ```testFind(double mortgage, double interest, double years)```
Prints the output of find in the format find(mortgage, interest, years) = principal
`static double` ```upperBound(double mortgage, double interest, double years)```
Calculates an upper bound for the principal

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### FindPrincipal

`public FindPrincipal()`
Method Detail

### find

```public static double find(double mortgage,
double interest,
double years)```
Calls findBetween 0 and the upper bound

Parameters:
`mortgage` - the monthly mortgage payment that the user can afford
`interest` - the interest rate
`years` - the length of the mortgage
Returns:
the maximum principal that the user can afford

### findBetween

```public static double findBetween(double mortgage,
double interest,
double years,
double lo,
double hi)```
Finds the ideal principal using a binary search of whether the monthly payment is too high or too low

Parameters:
`mortgage` - the monthly mortgage payment that the user can afford
`interest` - the interest rate
`years` - the length of the mortgage
`lo` - the lowest possible principal to examine
`hi` - the hightest possible principal to examine
Returns:
the maximum principal that the user can afford

### upperBound

```public static double upperBound(double mortgage,
double interest,
double years)```
Calculates an upper bound for the principal

Parameters:
`mortgage` - the monthly mortgage payment that the user can afford
`interest` - the interest rate
`years` - the length of the mortgage
Returns:
a value greater than the principal the user can afford

### testFind

```public static void testFind(double mortgage,
double interest,
double years)```
Prints the output of find in the format find(mortgage, interest, years) = principal

Parameters:
`mortgage` - the monthly mortgage payment that the user can afford
`interest` - the interest rate
`years` - the length of the mortgage

### main

`public static void main(java.lang.String[] args)`
Calls testFind with mortgage = 1200.00, interst = 7.00, and years = 30.0. Essentially used for testing