import java.text.*; public class Balance // // ************************************************ // // Philip J. Porvaznik // // Java programming I // // Finds balance remaining for car loan // using standard Amort formula // // problem #5 page 172 // // ************************************************ // { public static void main (String[] args) { // create decimal format DecimalFormat DF = new DecimalFormat("$0.00"); // KBalance is balance remaining for payment k // PAmount is monthly payment amount // Interest is interest rate // NTotal is total number of payments double KBalance; double PAmount = 165.25; double Interest = .09; double NTotal = 36.0; // display intro message System.out.println("This program calculates balance remaining using Amort forumula"); // display values for the balance calculations System.out.println("Monthly Payment = " + DF.format(PAmount)); System.out.println("Interest Rate = " + Interest); System.out.println("Total Payments = " + NTotal); // calculate Balance remaining after first payment KBalance = PAmount * ((1 - Math.pow((1 + Interest),(1 - NTotal))) / Interest); // display Balance after first payment System.out.println("Balance remaining after first payment = " + DF.format(KBalance)); // calculate Balance remaining after second payment KBalance = PAmount * ((1 - Math.pow((1 + Interest),(2 - NTotal))) / Interest); // display Balance after second payment System.out.println("Balance remaining after second payment = " + DF.format(KBalance)); // calculate Balance remaining after third payment KBalance = PAmount * ((1 - Math.pow((1 + Interest),(3 - NTotal))) / Interest); // display Balance after third payment System.out.println("Balance remaining after third payment = " + DF.format(KBalance)); // display end message System.out.println("End of program"); } }