【发布时间】:2013-12-03 11:57:42
【问题描述】:
包裹现值; 导入 java.util.Scanner;
公共类 PresentValue {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double P; // present value
double F; // future value
double r; // annual interest rate
double n; // number of years
P = presentValue();
F = futureValue();
r = annualInterest();
n = years();
System.exit(0);
}
public static double presentValue()
{
int input;
Scanner keyboard = new Scanner(System.in);
System.out.println("What is the presnt value of you savings account?");
return keyboard.nextDouble();
}
public static double futureValue()
{
int input;
Scanner keyboard = new Scanner(System.in);
System.out.println("How much do you want in your account in the future?");
return keyboard.nextDouble();
}
public static double annualInterest()
{
int input;
Scanner keyboard = new Scanner(System.in);
System.out.println("What is youe bank's interest rate?");
return keyboard.nextDouble();
}
public static double years()
{
int input;
Scanner keyboard = new Scanner(System.in);
System.out.println("How many years will the money in the bank?");
return keyboard.nextDouble();
}
public static double presentValue(double F, double r)
{
return F/(1+(r * r));
}
public static void show(double presentValue)
{
System.out.println(presentValue);
}
} 问题是写一个方法 presentValue 来执行这个计算。该方法应接受未来值、年利率和年数作为参数。它应该返回现值,即您今天需要存入的金额。在程序中演示该方法,让用户对公式中的项使用不同的值进行试验。
这里是公式 P = F/(1+r)^2
【问题讨论】:
-
你的问题是? (你已经展示了你的代码和原始问题,但你没有说什么是失败的。)作为风格问题,有点遗憾的是你有两个方法叫做
presentValue做非常不同的事情... -
抱歉,它不计算 presentValue。
-
那么它做什么呢?您的输入、预期输出和实际输出是多少?您采取了哪些步骤来诊断问题?目前,您的问题给人的印象是“这已损坏,请修复它”,而不是真正尝试自己修复并学习。
标签: java