Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Credit Card Payoff Calculator Key programming concepts: variables, input, fprint

ID: 3876399 • Letter: C

Question

Credit Card Payoff Calculator

Key programming concepts: variables, input, fprintf, basic math

Approximate lines of code: 13 (does not include comments, white space, or any of the code template)

Commands you can’t use: N/A

Program Inputs

• Balanced Owed: – User will always enter a positive numeric value

• APR Interest Rate (%): – User will always enter a positive numeric value

• Expected Monthly Payment: – User will always enter a positive numeric value

Program Outputs

• Repayment Table:

Option Payment Months Payoff XXX XXX XXX XXX

– Create a table that shows the total money needed to payoff the credit card for various options. Replace each XXX with the appropriate value. Use exactly 2 decimal places for all money values; also months should be rounded to the next highest whole month.

Assignment Details Your task is to recreate a popular online credit card payoff calculator! Given some initial information from the user, determine how quickly the user can repay his/her debt. Here is the app to base your code around:

Figure 1: https://www.creditkarma.com/calculators/debtrepayment-to

There are several key ideas to consider! First, the credit card interest rate is given as the APR (Annual Percentage Rate). This number is useful for comparing credit cards but doesn’t take into account compound interest that the credit card companies charge. This APR rate must be adjusted using the effective interest rate formula:

adjusted rate = (1 + rate 100 365 ) 30.4167 1

After adjusting the interest rate, we need the annuity payment formula to calculate different payment options:

payment = adjusted rate balance 1 (1 + adjusted rate) months

Finally, the payoff is calculated from the months found (including any fraction of the month):

payoff = payment months

Using the formulas above, create a table that describes three different payment options.

Note that each numeric value should be displayed with 2 decimal places.

• Option 1 shows the table results based on the user’s expected monthly payment

• Option 2 shows the same information except if the expected monthly payment is doubled

• Option 3 shows the monthly payment needed to payoff the credit card in 3 months

Please, note that most credit card apps (including the one from Credit Karma), display different results due to rounding and different compound interest formulas. Only use the formulas given here!

Sample Output The following test cases do not cover all possible scenarios (develop your own!) but should indicate if your code is on the right track. To guarantee full credit, your program’s output should exactly match the output below.

Test Case 1: Balanced Owed: 1873.47 APR Interest Rate (%): 14.49

Expected Monthly Payment: 35

Option Payment Months Payoff

1) $35.00 87 $3044.69

2) $70.00 33 $2279.54

3) $639.72 3 $1919.16

Test Case 2:

Balanced Owed: 551.03

APR Interest Rate (%): 17.99

Expected Monthly Payment: 20

Option Payment Months Payoff

1) $20.00 36 $717.83

2) $40.00 16 $622.44

3) $189.25 3 $567.76

Test Case 3:

Balanced Owed: 1569.04

APR Interest Rate (%): 16

Expected Monthly Payment: 30

Option Payment Months Payoff

1) $30.00 91 $2723.58

2) $60.00 33 $1945.41

3) $537.11 3 $1611.34

Test Case 4:

Balanced Owed: 1103.52

APR Interest Rate (%): 12.99

Expected Monthly Payment: 15

Option Payment Months Payoff

1) $15.00 149 $2234.43

2) $30.00 48 $1417.22

3) $375.87 3 $1127.62

Test Case 5:

Balanced Owed: 2919.83

APR Interest Rate (%): 10.99

Expected Monthly Payment: 50

Option Payment Months Payoff

1) $50.00 85 $4206.86

2) $100.00 35 $3415.86

3) $991.24 3 $2973.71

Explanation / Answer

import java.io.*;

import java.text.*;

public class dylab16100

{

public static void main (String args[]) throws IOException

{

BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

int choice;

double principal;

double yearlyInterest;

int paybackYears;

double monthlyPmt;

System.out.println("Select one of the following options");

System.out.println();

System.out.println("[1] Monthly Loan Payment Computation");

System.out.println("[2] Amortization Schedule");

System.out.println("[3] Credit Card Pay-Off Schedule");

System.out.println();

System.out.print("Enter your choice ===>> ");

choice = Integer.parseInt(input.readLine());

System.out.println();

switch (choice)

{

case 1:

System.out.print("Enter loan amount ===>> ");

principal = Double.parseDouble(input.readLine());

System.out.print("Enter annual percent ===>> ");

yearlyInterest = Double.parseDouble(input.readLine());

System.out.print("Enter years to pay back ===>> ");

paybackYears = Integer.parseInt(input.readLine());

Interest loan1 = new Interest(principal, yearlyInterest, paybackYears,0);

loan1.computePayment();

break;

case 2:

System.out.print("Enter principal balance ===>> ");

principal = Double.parseDouble(input.readLine());

System.out.print("Enter annual percent ===>> ");

yearlyInterest = Double.parseDouble(input.readLine());

System.out.print("Enter monthly payment ===>> ");

monthlyPmt = Double.parseDouble(input.readLine());

Interest loan2 = new Interest(principal, yearlyInterest, 0, monthlyPmt);

loan2.amortization();

break;

case 3:

System.out.print("Enter credit card balance ===>> ");

principal = Double.parseDouble(input.readLine());

System.out.print("Enter annual percent ===>> ");

yearlyInterest = Double.parseDouble(input.readLine());

Interest loan3 = new Interest(principal, yearlyInterest, 0, 0);

loan3.creditCard();

break;

}

System.out.println();

}

}

class Interest

{

private double principal;

private double amountLeft;

private double percent;

private int years;

private double monthlyPmt;

private int months;

private int pmtNr;

private double monthlyRate;

private double interestPmt;

private double principalPmt;

private double totalPmt;

private double totalInt;

private double round(double x)

{

x = x * 100 + 0.5;

x = (double) (Math.floor(x)) / 100;

return x;

}

public Interest(double la, double yi, int py, double mp)

{

principal = la;

percent = yi;

years = py;

monthlyPmt = mp;

monthlyRate = percent/1200;

months = years * 12;

pmtNr = 0;

}

public void computePayment()

{

System.out.println();

System.out.println("Loan Amount: " + principal);

System.out.println("Yearly Interest: " + percent);

System.out.println("Payback Years: " + years);

monthlyPmt = (monthlyRate*(Math.pow(( 1 + monthlyRate), months))) / (Math.pow(( 1 + monthlyRate), months) - 1) * principal;

monthlyPmt = Double.parseDouble(roundTwo(monthlyPmt));

System.out.println("Monthly Payment: " + monthlyPmt);

totalPmt = monthlyPmt * (years * 12);

System.out.println("Total Payments: " + roundOne(totalPmt));

totalInt = totalPmt - principal;

System.out.println("Total Interest: " + roundOne(totalInt));

System.out.println();

}

public String roundZero(double input)

{

DecimalFormat money = new DecimalFormat("0");

String roundZero = money.format(input);

return roundZero;

}

public String roundOne(double input)

{

DecimalFormat money = new DecimalFormat("0.0");

String roundOne = money.format(input);

return roundOne;

}

public String roundTwo(double input)

{

DecimalFormat money = new DecimalFormat("0.00");

String roundTwo = money.format(input);

return roundTwo;

}

public void amortization()

{

System.out.println();

System.out.println("Amortization Schedule");

System.out.println();

System.out.println("Loan Amount: " + roundZero(principal));

System.out.println("Yearly Interest: " + percent);

System.out.println("Monthly Payment: " + monthlyPmt);

amountLeft = principal;

percent = percent/100;

while( amountLeft > 0 )

{

interestPmt = (amountLeft * percent) / 12;

System.out.println(interestPmt);

principalPmt = monthlyPmt - interestPmt;

System.out.println(principalPmt);

amountLeft = amountLeft - principalPmt;

System.out.println(amountLeft);

totalPmt = totalPmt + monthlyPmt;

System.out.println(totalPmt);

months++;

if (amountLeft < principalPmt)

{

interestPmt = (amountLeft * percent) / 12;

monthlyPmt = amountLeft + interestPmt;

amountLeft = 0;

totalPmt = totalPmt + monthlyPmt;

months++;

}

}

System.out.println("Payback Months: " + months);

System.out.println("Total Payments: " + roundOne(totalPmt));

totalInt = totalPmt - principal;

System.out.println("Total Interest: " + roundOne(totalInt));

System.out.println();

}

public void creditCard()

{

//principal

//percent

percent = percent/100;

System.out.println();

System.out.println("Credit Card Pay-Off Schedule");

System.out.println();

System.out.println("Loan Amount: " + principal);

System.out.println("Yearly Interest: " + percent + "%");

System.out.println("Payback Months: ") + months;

System.out.println("Total Payments: ") + totalPmt;

System.out.println("Total Interest: ") + totalInt;

System.out.println();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote