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

Write a Java program that reads the amount of a mortgage payment (as a double) a

ID: 3791750 • Letter: W

Question

Write a Java program that reads the amount of a mortgage payment (as a double) and the amount still owed - the outstanding balance - on the mortgage (also as a double) and then displays the amount of the payment that goes towards interest and the amount that goes towards principal (e.g. the amount that goes towards reducing the debt). Assume that the annual interest rate is 4% (which is the current rate). Be sure to use a named constant for this interest rate. Note that mortgage payments are made monthly, so be sure to divide the annual rate by 12 when calculating the amount of the mortgage payment that goes towards interest.

Here is a sample transaction with the user:

Please enter your mortgage payment: $2500.00

Please enter ourstanding balance or mortgage: $450000.00

Of your $2,500.00 mortgage payment:

$1,500.00 goes to interest

$1,000.00 goes to principal

formula: 450000 * 0.04 / 12 = 1500

Explanation / Answer

Note:

Could you please check the output.I calculate the interest amount and pricipal amount for every month until the outstanding amount becomes zero.

______________________________

MortgagePayment.java

import java.text.DecimalFormat;
import java.util.Scanner;

public class MortgagePayment {

   public static void main(String[] args) {
       //Declaring constant
       final double interesrt=4.0;
  
       //Declaring variables
       double mortgage_payment,outstand_bal,monthly_interest,principal;
      
       //Scanner object is used to get the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       //DecimalFormat class is used to format the output
               DecimalFormat df=new DecimalFormat("#.##");
              
   //Getting the mortage payment entered by the user
       System.out.print("Please enter your mortgage payment: $");
       mortgage_payment=sc.nextDouble();
      
       //Getting the Outstanding balance entered by the user
       System.out.print("Please enter ourstanding balance or mortgage: $");
       outstand_bal=sc.nextDouble();
      
       //This loop continues to execute until the outstanding balance becomes zero
       while(outstand_bal>=0)
       {
           //calculating the monthly interest
           monthly_interest=outstand_bal*(4.0/1200);
          
           //calculating the principal amount for every month
           principal=mortgage_payment-monthly_interest;
          
           //Displaying the result
           System.out.println("Monthly Interest :"+df.format(monthly_interest)+" Principal :"+df.format(principal));
           outstand_bal-=mortgage_payment;
       }

   }

}

_________________

Output:

Please enter your mortgage payment: $2500
Please enter ourstanding balance or mortgage: $450000
Monthly Interest :1500 Principal :1000
Monthly Interest :1491.67 Principal :1008.33
Monthly Interest :1483.33 Principal :1016.67
Monthly Interest :1475 Principal :1025
Monthly Interest :1466.67 Principal :1033.33
Monthly Interest :1458.33 Principal :1041.67
Monthly Interest :1450 Principal :1050
Monthly Interest :1441.67 Principal :1058.33
Monthly Interest :1433.33 Principal :1066.67
Monthly Interest :1425 Principal :1075
Monthly Interest :1416.67 Principal :1083.33
Monthly Interest :1408.33 Principal :1091.67
Monthly Interest :1400 Principal :1100
Monthly Interest :1391.67 Principal :1108.33
Monthly Interest :1383.33 Principal :1116.67
Monthly Interest :1375 Principal :1125
Monthly Interest :1366.67 Principal :1133.33
Monthly Interest :1358.33 Principal :1141.67
Monthly Interest :1350 Principal :1150
Monthly Interest :1341.67 Principal :1158.33
Monthly Interest :1333.33 Principal :1166.67
Monthly Interest :1325 Principal :1175
Monthly Interest :1316.67 Principal :1183.33
Monthly Interest :1308.33 Principal :1191.67
Monthly Interest :1300 Principal :1200
Monthly Interest :1291.67 Principal :1208.33
Monthly Interest :1283.33 Principal :1216.67
Monthly Interest :1275 Principal :1225
Monthly Interest :1266.67 Principal :1233.33
Monthly Interest :1258.33 Principal :1241.67
Monthly Interest :1250 Principal :1250
Monthly Interest :1241.67 Principal :1258.33
Monthly Interest :1233.33 Principal :1266.67
Monthly Interest :1225 Principal :1275
Monthly Interest :1216.67 Principal :1283.33
Monthly Interest :1208.33 Principal :1291.67
Monthly Interest :1200 Principal :1300
Monthly Interest :1191.67 Principal :1308.33
Monthly Interest :1183.33 Principal :1316.67
Monthly Interest :1175 Principal :1325
Monthly Interest :1166.67 Principal :1333.33
Monthly Interest :1158.33 Principal :1341.67
Monthly Interest :1150 Principal :1350
Monthly Interest :1141.67 Principal :1358.33
Monthly Interest :1133.33 Principal :1366.67
Monthly Interest :1125 Principal :1375
Monthly Interest :1116.67 Principal :1383.33
Monthly Interest :1108.33 Principal :1391.67
Monthly Interest :1100 Principal :1400
Monthly Interest :1091.67 Principal :1408.33
Monthly Interest :1083.33 Principal :1416.67
Monthly Interest :1075 Principal :1425
Monthly Interest :1066.67 Principal :1433.33
Monthly Interest :1058.33 Principal :1441.67
Monthly Interest :1050 Principal :1450
Monthly Interest :1041.67 Principal :1458.33
Monthly Interest :1033.33 Principal :1466.67
Monthly Interest :1025 Principal :1475
Monthly Interest :1016.67 Principal :1483.33
Monthly Interest :1008.33 Principal :1491.67
Monthly Interest :1000 Principal :1500
Monthly Interest :991.67 Principal :1508.33
Monthly Interest :983.33 Principal :1516.67
Monthly Interest :975 Principal :1525
Monthly Interest :966.67 Principal :1533.33
Monthly Interest :958.33 Principal :1541.67
Monthly Interest :950 Principal :1550
Monthly Interest :941.67 Principal :1558.33
Monthly Interest :933.33 Principal :1566.67
Monthly Interest :925 Principal :1575
Monthly Interest :916.67 Principal :1583.33
Monthly Interest :908.33 Principal :1591.67
Monthly Interest :900 Principal :1600
Monthly Interest :891.67 Principal :1608.33
Monthly Interest :883.33 Principal :1616.67
Monthly Interest :875 Principal :1625
Monthly Interest :866.67 Principal :1633.33
Monthly Interest :858.33 Principal :1641.67
Monthly Interest :850 Principal :1650
Monthly Interest :841.67 Principal :1658.33
Monthly Interest :833.33 Principal :1666.67
Monthly Interest :825 Principal :1675
Monthly Interest :816.67 Principal :1683.33
Monthly Interest :808.33 Principal :1691.67
Monthly Interest :800 Principal :1700
Monthly Interest :791.67 Principal :1708.33
Monthly Interest :783.33 Principal :1716.67
Monthly Interest :775 Principal :1725
Monthly Interest :766.67 Principal :1733.33
Monthly Interest :758.33 Principal :1741.67
Monthly Interest :750 Principal :1750
Monthly Interest :741.67 Principal :1758.33
Monthly Interest :733.33 Principal :1766.67
Monthly Interest :725 Principal :1775
Monthly Interest :716.67 Principal :1783.33
Monthly Interest :708.33 Principal :1791.67
Monthly Interest :700 Principal :1800
Monthly Interest :691.67 Principal :1808.33
Monthly Interest :683.33 Principal :1816.67
Monthly Interest :675 Principal :1825
Monthly Interest :666.67 Principal :1833.33
Monthly Interest :658.33 Principal :1841.67
Monthly Interest :650 Principal :1850
Monthly Interest :641.67 Principal :1858.33
Monthly Interest :633.33 Principal :1866.67
Monthly Interest :625 Principal :1875
Monthly Interest :616.67 Principal :1883.33
Monthly Interest :608.33 Principal :1891.67
Monthly Interest :600 Principal :1900
Monthly Interest :591.67 Principal :1908.33
Monthly Interest :583.33 Principal :1916.67
Monthly Interest :575 Principal :1925
Monthly Interest :566.67 Principal :1933.33
Monthly Interest :558.33 Principal :1941.67
Monthly Interest :550 Principal :1950
Monthly Interest :541.67 Principal :1958.33
Monthly Interest :533.33 Principal :1966.67
Monthly Interest :525 Principal :1975
Monthly Interest :516.67 Principal :1983.33
Monthly Interest :508.33 Principal :1991.67
Monthly Interest :500 Principal :2000
Monthly Interest :491.67 Principal :2008.33
Monthly Interest :483.33 Principal :2016.67
Monthly Interest :475 Principal :2025
Monthly Interest :466.67 Principal :2033.33
Monthly Interest :458.33 Principal :2041.67
Monthly Interest :450 Principal :2050
Monthly Interest :441.67 Principal :2058.33
Monthly Interest :433.33 Principal :2066.67
Monthly Interest :425 Principal :2075
Monthly Interest :416.67 Principal :2083.33
Monthly Interest :408.33 Principal :2091.67
Monthly Interest :400 Principal :2100
Monthly Interest :391.67 Principal :2108.33
Monthly Interest :383.33 Principal :2116.67
Monthly Interest :375 Principal :2125
Monthly Interest :366.67 Principal :2133.33
Monthly Interest :358.33 Principal :2141.67
Monthly Interest :350 Principal :2150
Monthly Interest :341.67 Principal :2158.33
Monthly Interest :333.33 Principal :2166.67
Monthly Interest :325 Principal :2175
Monthly Interest :316.67 Principal :2183.33
Monthly Interest :308.33 Principal :2191.67
Monthly Interest :300 Principal :2200
Monthly Interest :291.67 Principal :2208.33
Monthly Interest :283.33 Principal :2216.67
Monthly Interest :275 Principal :2225
Monthly Interest :266.67 Principal :2233.33
Monthly Interest :258.33 Principal :2241.67
Monthly Interest :250 Principal :2250
Monthly Interest :241.67 Principal :2258.33
Monthly Interest :233.33 Principal :2266.67
Monthly Interest :225 Principal :2275
Monthly Interest :216.67 Principal :2283.33
Monthly Interest :208.33 Principal :2291.67
Monthly Interest :200 Principal :2300
Monthly Interest :191.67 Principal :2308.33
Monthly Interest :183.33 Principal :2316.67
Monthly Interest :175 Principal :2325
Monthly Interest :166.67 Principal :2333.33
Monthly Interest :158.33 Principal :2341.67
Monthly Interest :150 Principal :2350
Monthly Interest :141.67 Principal :2358.33
Monthly Interest :133.33 Principal :2366.67
Monthly Interest :125 Principal :2375
Monthly Interest :116.67 Principal :2383.33
Monthly Interest :108.33 Principal :2391.67
Monthly Interest :100 Principal :2400
Monthly Interest :91.67 Principal :2408.33
Monthly Interest :83.33 Principal :2416.67
Monthly Interest :75 Principal :2425
Monthly Interest :66.67 Principal :2433.33
Monthly Interest :58.33 Principal :2441.67
Monthly Interest :50 Principal :2450
Monthly Interest :41.67 Principal :2458.33
Monthly Interest :33.33 Principal :2466.67
Monthly Interest :25 Principal :2475
Monthly Interest :16.67 Principal :2483.33
Monthly Interest :8.33 Principal :2491.67
Monthly Interest :0 Principal :2500

_____________thank You

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