2017-01-02 50 views
-3

我正在使用以下代碼來獲得加拿大抵押貸款付款,並在第15行中收到「無法解析爲變量」消息。我做錯了什麼? 我的電腦設置爲加拿大法語。使用NumberFormat時,語言環境無法解析爲變量爲什麼?

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.text.NumberFormat; 
import java.util.Currency; 

public class Mortgage { 
    public static void main(String args[]) throws IOException { 
     NumberFormat canadaFrench = NumberFormat.getCurrencyInstance(Locale.CANADA_FRENCH); 
     BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); 
     double principal, rate, ratePercent, rateFinal; 
     int years, n; 
     final int paymentsPerYear = 12; 
     final int timesPerYearCalculated = 12; 
     double effectiveAnnualRate; 
     double payment; 

     System.out.print("How much are you borrowing?   "); 
     principal = Double.parseDouble(keyboard.readLine()); 
     System.out.print("What's the interest rate?    "); 
     ratePercent = Double.parseDouble(keyboard.readLine()); 
     rate = ratePercent/100.00; 
     System.out.print("How many years are you taking to pay? "); 
     years = Integer.parseInt(keyboard.readLine()); 
     System.out.println("------------------------------"); 

     n = paymentsPerYear * years; 
     // Hypothèque canadienne avec un taux capitalisé deux fois l'an, 
     // d'où le calcul de l'équivalance des taux! 
     rateFinal = 12.0 * (Math.pow(1.0 + (rate/2.0), (2.0/12.0)) - 1.0); 
     effectiveAnnualRate = rateFinal/paymentsPerYear; 

     payment = principal * (effectiveAnnualRate/(1 - Math.pow(1 + effectiveAnnualRate, -n))); 

     System.out.print("Your monthly payment is    "); 
     System.out.println(canadaFrench.format(payment)); 
     System.out.println(); 
    } 
} 
+3

是否缺少進口java.util.Locale中;聲明 –

回答

1

您需要添加import java.util.Locale;

+0

謝謝卡爾。我有貨幣,但沒有區域!!!!! – Jacques

相關問題