package y2kmz.com.daikuan;//说明程序出现的类在该包中 import javax.swing.JOptionPane;//导入javax.swing这个包中的JOptionPane这个类 public class exercise_1_2 {//公共类exercise public static void main(String[] args) { // Enter yearly interest rate String annualIntrestRateString = JOptionPane.showInputDialog( "输入利率,如 8.11:");//输入String类型的变量annuealInterstRateString(年利率) // Convert string to double double annualInterestRate = Double.parseDouble(annualIntrestRateString);//annualInterestRate,利率 //将String类型变量annualInterestRate转换为Double型变量() // Obtain monthly interest rate double monthlyInterestRate = annualInterestRate/1200; //月利率等于年利率除以1200 // Enter number of years String numOfYearsString = JOptionPane.showInputDialog( "输入贷款年限, /n如 5:");//贷款年限,numOfYearsString //输入String类型的numOfYearsString(贷款年限) // Convert string to int int numOfYears = Integer.parseInt(numOfYearsString); //将String类型变量numOfYears转换成Int类型 String investmentAmountString = JOptionPane.showInputDialog( "输入贷款总额, 如 120000.00:");//investmentAmountString,贷款总额 //输入String类型变量investmentString(贷款总量) // Convert string to double double investmentAmount = Double.parseDouble(investmentAmountString); //将字符串类型的贷款总量转换成双精度浮点型 double futureValue = (investmentAmount * monthlyInterestRate) /(1-1/Math.pow((1+monthlyInterestRate),(numOfYears*12))); //double类型futureValue=****** JOptionPane.showMessageDialog(new JOptionPane(), "月偿还金额:"+((int)(futureValue * 100) / 100.0)+" 总偿还金额:"+((int)(futureValue * 12 * numOfYears * 100) / 100.0)); //输出 System.exit(0);//程序结束 } }