BTC USD 86,658.1 Gold USD 4,345.18
Time now: Jun 1, 12:00 AM

java

ruzana

Active Member
Messages
2,307
Joined
Jan 3, 2011
Messages
2,307
Reaction score
1
Points
25
salam..
tlg tgkkan coding mmbe ni..
ad 2 error laa..




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 = loanTerm / 12;
intRate = (intRate * .01);
monthlyPay = loanAmt * intRate / (1 - Math.pow(1 + intRate, - loanTerm));

// displays results
System.out.println();
System.out.println("Mortgage Payment For $" + loanAmt + " Length of Contract " + loanTerm + " years at");
System.out.println("a " + (money2.format(intRate) + " Interest Rate = " + (money.format(monthlyPay))));

}

while (x <3);

}
}
}
 
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");
-----------------------------------------------
dh ada 'money' kt atas. ubah salah satu ke nama lain.

--------------------------------------------
}

while (x <3);

}
}
}
-----------------------------------------------
ubah jdi mcm ne.

}



}
while (x <3);
}
}
 
Code:
System.out.println("\n\nYour Mortgage Payment " + [B][COLOR="Blue"]twoplaces[/COLOR][/B].format(payment) + "\n\nfor the " + length[x] + " Year Contract "); //Display Text to explane values

yang kat sini mana datangnye object twoplaces? mungkin ruzana nak tulis money/money2/money3 kot... kan?
 
Last edited:
Back
Top
Log in Register