2017-05-19 32 views
0

我試圖做一個程序,用原理,利率和年份計算賬戶的複合利息。我試圖用對話框來做/如果原則是積累的話,程序的輸出就是投資回報。銀行利息Q

林停留在計算部分,請大家幫忙

package firstAssignment; 

import java.util.Scanner; 

import javax.swing.JOptionPane; 

public class thinkingQuestion { 

public static void main(String[] args) { 

//Banking program that asks user for the amount of money they wish to invest in a 
//compound interest account (principle), the interest rate (percent value) and the time frame (years). 

    Scanner in= new Scanner(System.in); 

    String principle, interestVal, years; 
    int newPrinciple,newYears; 
    double total; 

     principle=JOptionPane.showInputDialog("How much money would you like to invest?"); 

     interestVal=JOptionPane.showInputDialog("What's the interest rate?"); 

     years=JOptionPane.showInputDialog("How many years?"); 

     //convert from String to integer 

     newPrinciple=Integer.parseInt(principle); 
     newYears=Integer.parseInt(years); 

     double newInterestVal=Integer.parseInt(interestVal); 

     total=JOptionPane.PLAIN_MESSAGE(newPrinciple*Math.pow(1+ newInterestVal, newYears), newYears); 
+0

我特別卡上共計一部分,因爲它不會讓我使用利息公式的問題。 –

+0

total = newPrinciple * Math.pow((1 + newInterestVal),newYears); \t \t JOptionPane.showMessageDialog(NULL,總+ 「」, 「總計」,JOptionPane.INFORMATION_MESSAGE);你也必須輸入複合週期數n。這裏我假定n = 1家的 – Kangkan

+0

其表示向將所述串中的錯誤爲int,特別是線31 –

回答

0

我刪除SOMO變量,你不需要,我認爲主要的問題是在作秀消息Java語法。在這裏,你可以看到一個教程:

https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html

import javax.swing.JOptionPane; 

public class InterestBanking { 

    public static void main(String[] args) { 

     // Banking program that asks user for the amount of money they wish to 
     // invest in a 
     // compound interest account (principle), the interest rate (percent 
     // value) and the time frame (years). 

     String principle, interestVal, years; 
     float newPrinciple, newYears; 

     principle = JOptionPane.showInputDialog("How much money would you like to invest?"); 

     interestVal = JOptionPane.showInputDialog("What's the interest rate?"); 

     years = JOptionPane.showInputDialog("How many years?"); 

     // convert from String to integer 

     newPrinciple = Float.parseFloat(principle); 
     newYears = Float.parseFloat(years); 

     double newInterestVal = Float.parseFloat(interestVal); 

     //You could change your calculation here if this isn't the need formula 
     double interest = newPrinciple * Math.pow(1 + newInterestVal, newYears); 

     //you were assigning the result to a total variable. That's not neccesary 
     JOptionPane.showMessageDialog(null, "Interest:" + NumberFormat.getCurrencyInstance(new Locale("en", "US")).format(interest) + " In years: " + newYears); 
    } 
} 
+0

及其測試時,它示出了錯誤,它說,它的轉換字符串一倍或INT線。 –

+0

您使用的是哪個版本的java? – sirandy

+0

日食kepler,我的學校不會讓我們使用更高版本 –