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

--- Please read the question in detail in \"JAVA SCRIPT\", then answer as reques

ID: 3708172 • Letter: #

Question

--- Please read the question in detail in "JAVA SCRIPT", then answer as requested and as smaple output shows ( I paying for these tutorials.... )

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Design and implement a program that will allow us to determine the length of time needed to pay off a credit card balance, as well as the total interest paid.

The program must implement the following functions:

displayWelcome

This function should display the welcome message to the user explaining what the program does.

calculateMinimumPayment

This function calculates the minimum payment. It should take balance and minimum payment rate as arguments and return the minimum payment.

So the value you display for minimum payment is the value you get from this method. Do not use a literal hardcoded value when you display the minimum payment!

displayPayments

This function displays the actual payment schedule. It should take the balance and monthly interest rate as arguments.

Use the 1500, 18% and 2% literal values below.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

See the sample execution below:

This program will determine the time to pay off a credit card and the interest paid based on the current balance,

the interest rate, and the monthly payments made.

Balance on your credit card: 1500

Interest Rate: 18

Assuming a minimum payment of 2% of the balance ($20 min)

Your minimum payment would be $ 30.00

PAYOFF SCHEDULE

_________________

Cont.

Year Balance Payment Number Interest Paid Minimum Payment 1 $ 1,492.50 1 $         22.50 $                      30.00 $ 1,485.04 2 $         44.89 $                      29.85 $ 1,477.61 3 $         67.16 $                      29.70 $ 1,470.22 4 $         89.33 $                      29.55 $ 1,462.87 5 $      111.38 $                      29.40 $ 1,455.56 6 $      133.32 $                      29.26 $ 1,448.28 7 $      155.16 $                      29.11 $ 1,441.04 8 $      176.88 $                      28.97 $ 1,433.83 9 $      198.50 $                      28.82 $ 1,426.67 10 $      220.00 $                      28.68 $ 1,419.53 11 $      241.40 $                      28.53 $ 1,412.43 12 $      262.70 $                      28.39 2 $ 1,405.37 13 $      283.88 $                      28.25 $ 1,398.35 14 $      304.96 $                      28.11 $ 1,391.35 15 $      325.94 $                      27.97 $ 1,384.40 16 $      346.81 $                      27.83 $ 1,377.47 17 $      367.58 $                      27.69 $ 1,370.59 18 $      388.24 $                      27.55 $ 1,363.73 19 $      408.80 $                      27.41 $ 1,356.92 20 $      429.25 $                      27.27 $ 1,350.13 21 $      449.61 $                      27.14 $ 1,343.38 22 $      469.86 $                      27.00 $ 1,336.66 23 $      490.01 $                      26.87 $ 1,329.98 24 $      510.06 $                      26.73

Explanation / Answer

Code

HTML file:

<!DOCTYPE html>
< html>
< head>
< title>Interest Calculator</title>
< script src="script.js"></script>
< /head>
< body>
< /body>
< /html>?

Javascript file (script.js):

function displayWelcome()

{

document.write("This program will determine the time");

    document.write(" to pay off a credit card and the");

    document.write(" interest paid based on the current");

    document.write(" balance, the interest rate, and the");

    document.write(" monthly payments made.");

}

//Define the function to calculate the min. payment.

function calculateMinimumPayment(credit_bal, min_pay_per)

{

    //Create and initialize the variable.

    var bal_per = credit_bal * min_pay_per;

    //Check the value of the percentage balance and

    // return the maximum value.

    if (20 > bal_per)

    {

        return 20;

    }

    else

    {

        return bal_per;

    }

}

//Define the function to display the payments.

function displayPayments(credit_bal, int_rate, min_pay)

{

    //Display the values.

    document.write("<br>" + "Balance on your credit card:"

        + credit_bal.toFixed(2));

    document.write("<br>" + "Interest Rate: "

        + (int_rate * 100));

    document.write("<br>"+"Assuming a minimum payment of");

    document.write(" 2% of the balance ($20 min)");

    document.write("<br>" +

        "Your minimum payment would be $ " + min_pay);

    document.write("<br>" + "PAYOFF SCHEDULE ");

    document.write("<BR>------------------------------");

    document.write("<br>" +

      "Year Balance Payment Num Interest Paid");

    //Create and initialize the variables.

    var num = 0;

    var interestPaid = 0;

    var year = 1;

    //Start the loop.

    while (credit_bal > 0)

    {

        //Check if the value is shown for all the months.

        if (num % 12 === 0)

        {

            //Display the year.

            document.write("<br>" + year + " ");

            //Increase the year.

            year = year + 1;

        }

        //Calculate the interest paid.

        interestPaid = interestPaid +

            (credit_bal * int_rate) / 12;

        //Calculate the balance.

        credit_bal = credit_bal - (min_pay -

            (credit_bal * int_rate) / 12);

        //Check if the balance is less than 0.

        if (credit_bal < 0)

        {

            //Set the balance to 0.

            credit_bal = 0;

        }

        //Display the values.

        document.write(credit_bal.toFixed(2) + " " +

            (num + 1) + " " + interestPaid.toFixed(2) +

            "<br>");

        //Increate the num.

        num = num + 1;

    }

}

//Define the function onload.

window.onload = function ()

{

    //Create and initialize the variables.

    var credit_bal = 1500;

    var min_pay_per = 0.02;

    var int_rate = 0.18;

    //Call the function to display the heading.

    displayWelcome();

    //Call the function to calculate the min. payment.

    var min_pay = calculateMinimumPayment

        (credit_bal, min_pay_per);

    //Call the function to display the payments.

    displayPayments(credit_bal, int_rate, min_pay);