Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @version 1.0
- * @author Joe Stein
- */
- public class TidBit
- {
- private final double PAYMENT_RATE = .05;
- private final double DOWN_PAYMENT_RATE = .10;
- private final double INITIAL_PRICE;
- private final double DOWN_PAYMENT;
- private final double MONTHLY_PAYMENT;
- private double curr_balance;
- private double curr_interest;
- private double curr_principal;
- private int curr_month;
- private double curr_pmt;
- // principal = not with interest
- /**
- * Creates a tidbit given the initial payment. If the initial payment is less
- * than 0, the tidbit will use the absolute value of the number.
- * @param p the intial payment
- */
- public TidBit(double p)
- {
- if (p < 0)
- {
- p = Math.abs(p);
- }
- INITIAL_PRICE = p;
- DOWN_PAYMENT = p * DOWN_PAYMENT_RATE;
- MONTHLY_PAYMENT = (PAYMENT_RATE)*(INITIAL_PRICE - DOWN_PAYMENT);
- curr_balance = (INITIAL_PRICE - DOWN_PAYMENT);
- }
- /**
- * Returns the current balance.
- * @return the current balance
- */
- public double getBalance()
- {
- return curr_balance;
- }
- /**
- * Returns the principal payment due for this month.
- * @return the principal payment due for this month
- */
- public double getPrincipal()
- {
- return curr_principal;
- }
- /**
- * Returns the interest due for this month.
- * @return the interest due for this month
- */
- public double getInterest()
- {
- return curr_interest;
- }
- /**
- * Returns the total payment due for this month.
- * @return the total payment due for this month
- */
- public double getPayment()
- {
- return curr_pmt;
- }
- /**
- * Returns the month that this tidbit payment is on.
- * @return the month that this tidbit payment is on
- */
- public int getMonth()
- {
- return curr_month;
- }
- /**
- * Advances a month on the payment and calculates the interest owed,
- * principal, payment, etc.
- */
- public void nextMonth()
- {
- curr_interest = curr_balance*PAYMENT_RATE/12;
- curr_principal = MONTHLY_PAYMENT - curr_interest;
- curr_month++;
- if (MONTHLY_PAYMENT >= curr_balance) // if balance left < monthly payment
- {
- curr_principal = curr_balance; // pay the rest of the balance
- curr_pmt = curr_principal + curr_interest;
- curr_balance = 0;
- } else
- {
- curr_balance -= curr_principal;
- curr_pmt = MONTHLY_PAYMENT;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement