- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码有问题,我不确定为什么,有人可以帮我吗?我正在尝试重构我的主要方法,并且由于这个错误,我的想法也不允许我这样做。该错误位于第24行,我已在其中添加了注释。根据要求,我提供了错误消息和计算余额方法。
Error Message
import java.text.NumberFormat;
import java.util.Scanner;
public class Main {
final static int Months_In_Year = 12;
final static int Percent = 100;
public static void main(String[] args) {
int principal = (int) readNumber("Principal: ", 1000, 1_000_000);
double annualInterest = (double) readNumber("Annual Interest Rate: ", 1, 30);
byte years = (byte) readNumber("Period(years): ", 1, 30);
printMortgage(principal, annualInterest, years);
System.out.println("PAYMENT SCHEDULE");
System.out.println("--------------------");
for( short month = 1; month < years * Months_In_Year; month++){
double balance = calculateBalance(principal, annualInterest, years, month); // error here
System.out.println(NumberFormat.getCurrencyInstance().format(balance));
}
}
private static void printMortgage(int principal, double annualInterest, byte years) {
double mortgage = calculateMortgage(principal, annualInterest, years);
String mortgageCalculated = NumberFormat.getCurrencyInstance().format(mortgage);
System.out.println("MORTGAGE");
System.out.println("---------------------");
System.out.println("Monthly Payments: " + mortgageCalculated);
}
public static double readNumber(String prompt, double min, double max) {
Scanner scanner = new Scanner(System.in);
double value;
while (true) {
System.out.println(prompt);
value = scanner.nextDouble(); //change to float, don't need as much memory
if ((value >= min) && (value <= max))
break;
System.out.println("Pick value between " + min + " and " + max);
}
return value;
}
public static double calculateMortgage(
int principal,
double annualInterest,
byte years) {
double monthlyInterest = annualInterest / (Percent * Months_In_Year);
double numberOfPayments = years * Months_In_Year;
double mortgage = principal
* (monthlyInterest * Math.pow(1 + monthlyInterest, numberOfPayments)
/ Math.pow(1 + monthlyInterest, numberOfPayments));
return mortgage;
}
public static double calculateBalance (
int principal,
double mortgage,
double annualInterest,
byte years,
short numberOfPaymentsMade ){
double monthlyInterest = annualInterest / (Percent * Months_In_Year);
double numberOfPayments = years * Months_In_Year;
double balance =(double) principal *
(Math.pow(1 + monthlyInterest, numberOfPayments) - Math.pow(1 + monthlyInterest, numberOfPayments)
/ (Math.pow(1 + monthlyInterest, numberOfPayments) - 1));
return balance;
}
}
最佳答案
在下面的代码中
public static double calculateBalance (
int principal,
double mortgage,
double annualInterest,
byte years,
short numberOfPaymentsMade ){
double monthlyInterest = annualInterest / (Percent * Months_In_Year);
double numberOfPayments = years * Months_In_Year;
double balance =(double) principal *
(Math.pow(1 + monthlyInterest, numberOfPayments) - Math.pow(1 + monthlyInterest, numberOfPayments)
/ (Math.pow(1 + monthlyInterest, numberOfPayments) - 1));
return balance;
}
}
public static double calculateBalance (
int principal,
double annualInterest,
byte years,
short numberOfPaymentsMade ){
double monthlyInterest = annualInterest / (Percent * Months_In_Year);
double numberOfPayments = years * Months_In_Year;
double balance =(double) principal *
(Math.pow(1 + monthlyInterest, numberOfPayments) - Math.pow(1 + monthlyInterest, numberOfPayments)
/ (Math.pow(1 + monthlyInterest, numberOfPayments) - 1));
return balance;
}
}
关于java - 明确转换: java时发生未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59097189/
我在 linux 上工作。我对windows没有太多想法。 windows中文件的权限是如何组织的?我们在unix中是否有像chmod这样的api来更改权限? 最佳答案 对于 Windows,有一个名
应用程序编程接口(interface) (API) 是一组用于访问基于 Web 的软件应用程序的编程指令和标准。 如果出现 ,有人可以向我解释一下吗?谷歌地图 或 优酷 这是API哪个是softwar
我有两个应用程序,A 和 B,它们使用 android 库 C。B 有一个服务 A 想通过 C 使用,例如 在我的库中有一个类试图将它绑定(bind)到服务,
我正在正常或安全模式下启动相机应用程序,具体取决于使用我的应用程序执行的手势,但一旦用户选择应用程序并点击始终,则没有选项可以更改默认值,即使是从 Android 的设置菜单中也是如此. camera
我有一个数据集,本质上是一个稀疏二进制矩阵,表示两个集合的元素之间的关系。例如,让第一组是人(用他们的名字表示),例如像这样的东西: people = set(['john','jane','mike
何为pythonic? pythonic如果翻译成中文的话就是很python。很+名词结构的用法在中国不少,比如:很娘,很国足,很CCTV等等。 我的理解为,很+名词表达了一种特殊和强调的意味。
某些 Prolog 目标的确定性成功问题已经一次又一次地出现在 - 至少 - 以下问题: Reification of term equality/inequality Intersection an
我指的是 DateTime.TryParse(string s, out DateTime result) 重载,它尝试从字符串中解析 DateTime - 没有特定的格式正在指定。 我可以从http
2020 年 04 月 10 日,《中共中央国务院关于构建更加完善的要素市场化配置体制机制的意见》正式公布,将数据确立为五大生产要素(土地、资本、劳动力以及技术)之
有人可以解释一下 NSNotification 的 addObserver 函数中 notificationSender 的用途吗? 这是 Apple 文档的解释: notificationSende
我是一名优秀的程序员,十分优秀!