【发布时间】:2014-03-28 10:45:15
【问题描述】:
所以,我正在为学校做这个项目,我觉得它真的很简单,但我真的很笨。我需要有两种方法;一个只做我想做的计算,另一个是用户输入数字并显示计算方法的答案。课程网站上的示例让我们很容易理解如何使用一个用户输入的变量,而不是像我需要的 3 个;我还需要能够将它们全部相乘并在等式中使用它们。到目前为止,这是我所拥有的:
import java.util.*;
import java.text.*;
public class Lab3StarterCodeExperimental {
public static final Scanner CONSOLE = new Scanner(System.in);
public static double compoundInterest(double accountValue) {
double firstCalc = accountValue * 150;
return firstCalc;
}
public static void main(String [] args) {
//print title of lab
System.out.println("Lab 3");
//get user input (present value of account, interest rate, # years, payment per year)
System.out.print("Enter present value of the account: ");
double presentValue = CONSOLE.nextDouble();
System.out.print("Enter the interest rate of the account: ");
double interestRate = CONSOLE.nextDouble();
System.out.print("Enter the number of years: ");
double numOfYears = CONSOLE.nextDouble();
//calculate future value of account
double fvAccount = compoundInterest(presentValue);
//calculate future value of annuity
//print everything
System.out.println("Fake Variable is " + presentValue);
System.out.println("Future value of account is " + fvAccount);
}
}
非常感谢任何帮助!
【问题讨论】:
标签: java variables methods parameters console