Variable 'interest_rate' might not have been initialized Write a program Loan Calculator that input customer name, principal loan, term or period. Compute the interest per annum, total interest, the total payable loan and the monthly amortization.
Rate Interest Rate
1-3 year 6.500%
5 year 7.270%
10 year 8.035%
15 year 8.585%
20 year 8.800%
25 year 9.050%
import java.util.Scanner;
public class Assessment15 {
public static void main (String [] args){
String sname;
double p_loan,term,interest_rate,interest_per_annum,t_interest, amortization;
Scanner sc = new Scanner(System.in);
System.out.println("Customer name:");
sname = sc.nextLine();
System.out.println("Principal loan:");
p_loan = sc.nextDouble();
System.out.println("Term or period");
term = sc.nextInt();
if (term >= 1 && term <= 3 ) {
interest_rate = 6.500;
}else if (term >= 4) {
interest_rate = 7.270;
}else if (term >= 10) {
interest_rate = 8.035;
}else if (term >= 15) {
interest_rate = 8.585;
}else if (term >= 20) {
interest_rate = 8.800;
}else if (term >= 25) {
interest_rate = 9.050;
}
interest_per_annum = interest_rate / term;
t_interest = p_loan * interest_rate;
amortization = (p_loan + interest_rate) / term;
System.out.println("Customer Name: " + sname);
System.out.println("Interest per annum: " + interest_per_annum);
System.out.println("Total payable loan: " + term / interest_rate );
System.out.println("Monthly amortization: " + amortization );
}
}
Aucun commentaire:
Enregistrer un commentaire