【发布时间】:2017-10-19 14:54:26
【问题描述】:
我正在尝试制作一个程序,用本金、利率和年数计算帐户的复利。我试图用对话框来做这件事/如果原则留给积累,程序会输出投资回报。
我卡在计算部分,请帮忙
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); JOptionPane.showMessageDialog (null, total+"", "Total", JOptionPane.INFORMATION_MESSAGE);您还必须输入复利期数 n。这里我假设 n=1
-
它显示将字符串转换为 int 的错误,尤其是第 31 行
标签: java double joptionpane banking