我試圖做一個程序,用原理,利率和年份計算賬戶的複合利息。我試圖用對話框來做/如果原則是積累的話,程序的輸出就是投資回報。銀行利息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);
我特別卡上共計一部分,因爲它不會讓我使用利息公式的問題。 –
total = newPrinciple * Math.pow((1 + newInterestVal),newYears); \t \t JOptionPane.showMessageDialog(NULL,總+ 「」, 「總計」,JOptionPane.INFORMATION_MESSAGE);你也必須輸入複合週期數n。這裏我假定n = 1家的 – Kangkan
其表示向將所述串中的錯誤爲int,特別是線31 –