Faizura Fadzil 0 Report post Posted October 18, 2011 salam kawan-2, tlg tgkkan coding ni . ada dua error . import java.io.*; import java.text.*; import java.text.DecimalFormat; public class WK5IA { public static void main(String[] args) throws IOException { // declare variables int loanAmt = 200000; // principal loan amount int[] loanTerm = {84, 180 ,360}; // loan term for 7 years, 15 years, and 30 years int loanYears; // indicates the loan term in years double[] intRate = {5.35, 5.50, 5.75}; // interest rates for 7 years, 15 years, and 30 years double newIntRate; // displays interest rate calculation double monthlyPay = 0; // displays monthly payment calculation DecimalFormat money = new DecimalFormat("$#,###.00"); // displays mortgage in decimal format DecimalFormat money2 = new DecimalFormat("0.00%"); //displays interest rate in decimal format DecimalFormat money = new DecimalFormat("#,###.00"); InputStreamReader reader = new InputStreamReader(System.in); BufferedReader object = new BufferedReader(reader); double loan = 200000.00; //Array int[] length = new int[3]; length[0]=7; length[1]=15; length[2]=30; double [] interest = new double [3]; interest[0] = .0535; interest[1] = .0550; interest[2] = .0575; int x = 0; do //Do Statement { double payment = (loan*(interest[x]/12))/(1-(Math.pow(1/(1+(interest[x]/12)),(length[x]*12)))); //Display Math System.out.println("\n\nYour Mortgage Payment " + twoplaces.format(payment) + "\n\nfor the " + length[x] + " Year Contract "); //Display Text to explane values x++; // displays messages to indicate purpose of program and conditions in the console window System.out.println(); System.out.println("Mortgage Payment Calculator"); System.out.println(); System.out.println("Calculate three separate mortgage payments for a $" + loanAmt); System.out.println("Length of Contract and Interest Rate: (1) 7 years @ 5.35%"); System.out.println("\t\t\t\t\t (2) 15 years @ 5.50%"); System.out.println("\t\t\t\t\t (3) 30 years @ 5.75%"); System.out.println(); System.out.println("The results:"); int i; for (i = 0; i <= 2; i++) { loanTerm[i] = loanTerm[i] / 12; intRate[i] = (intRate[i] * .01); monthlyPay = loanAmt * intRate[i] / (1 - Math.pow(1 + intRate[i], - loanTerm[i])); // displays results System.out.println(); System.out.println("Mortgage Payment For $" + loanAmt + " Length of Contract " + loanTerm[i] + " years at"); System.out.println("a " + (money2.format(intRate[i]) + " Interest Rate = " + (money.format(monthlyPay)))); } while (x <3); } } } Quote Share this post Link to post Share on other sites
'atiq 0 Report post Posted November 1, 2011 [CODE] package Saja2; import java.io.*; import java.text.*; import java.text.DecimalFormat; public class WK5IA { public static void main(String[] args) throws IOException { // declare variables int loanAmt = 200000; // principal loan amount int[] loanTerm = { 84, 180, 360 }; // loan term for 7 years, 15 years, // and 30 years int loanYears; // indicates the loan term in years double[] intRate = { 5.35, 5.50, 5.75 }; // interest rates for 7 years, // 15 years, and 30 years double newIntRate; // displays interest rate calculation double monthlyPay = 0; // displays monthly payment calculation DecimalFormat money = new DecimalFormat("$#,###.00"); // displays // mortgage in // decimal // format DecimalFormat money2 = new DecimalFormat("0.00%"); // displays interest // rate in decimal // format InputStreamReader reader = new InputStreamReader(System.in); BufferedReader object = new BufferedReader(reader); double loan = 200000.00; // Array int[] length = new int[3]; length[0] = 7; length[1] = 15; length[2] = 30; double[] interest = new double[3]; interest[0] = .0535; interest[1] = .0550; interest[2] = .0575; int x = 0; do // Do Statement { double payment = (loan * (interest[x] / 12)) / (1 - (Math.pow(1 / (1 + (interest[x] / 12)), (length[x] * 12)))); // Display Math System.out.println("\n\nYour Mortgage Payment " + payment + "\n\nfor the " + length[x] + " Year Contract "); // Display // Text // to // explane // values x++; // displays messages to indicate purpose of program and conditions // in the console window System.out.println(); System.out.println("Mortgage Payment Calculator"); System.out.println(); System.out .println("Calculate three separate mortgage payments for a $" + loanAmt); System.out .println("Length of Contract and Interest Rate: (1) 7 years @ 5.35%"); System.out.println("\t\t\t\t\t (2) 15 years @ 5.50%"); System.out.println("\t\t\t\t\t (3) 30 years @ 5.75%"); System.out.println(); System.out.println("The results:"); int i; for (i = 0; i <= 2; i++) { loanTerm[i] = loanTerm[i] / 12; intRate[i] = (intRate[i] * .01); monthlyPay = loanAmt * intRate[i] / (1 - Math.pow(1 + intRate[i], -loanTerm[i])); // displays results System.out.println(); System.out.println("Mortgage Payment For $" + loanAmt + " Length of Contract " + loanTerm[i] + " years at"); System.out .println("a " + (money2.format(intRate[i]) + " Interest Rate = " + (money .format(monthlyPay)))); } } while (x < 3); } } [/CODE] Quote Share this post Link to post Share on other sites
carnine9 38 Report post Posted December 1, 2011 (edited) W'salam. Using an IDE helps you find these things. Try Eclipse if you can figure it out. it is free to all. 3 errors: [b]DecimalFormat money[/b] is defined twice [b]twoplaces[/b] is an undefined variable your [b]while[/b] statement should be after the curly bracket ending the [b]do[/b] statement and not at the end of your [b]for[/b] statement. there are 5 warnings, but that's just for the unused import and variables. Edited December 1, 2011 by carnine9 Quote Share this post Link to post Share on other sites