在我的作业问题中,我应该根据用户提供的贷款金额利率和贷款期限来计算每月的贷款支付。这是使用意图来完成的。
当我运行应用程序时,变量的值永远不会从 0 改变,然后它会转到应用程序的第二页,应该显示结果,但它说 NaN,应该显示结果。
我对 Android 开发非常陌生,我不知道问题出在哪里,所以我发布了我拥有的所有主要 Java 代码。
名为Loan.java 的类
package com.example.collegeloanpayoffcalculator;
public class Loan
{
public static double loanAmount = 0.0;
public static double interestRate = 0.0;
public static int loanDuration = 0;
//public static double monthlyPayment = 0.0;
public double amount;
public double interest;
public double duration;
//public double payment;
public Loan() {}
public Loan(double amount, double interest, double duration)
{
this.amount = amount;
this.interest = interest;
this.duration = duration;
}
}
名为MainActivity.java的类
public void calculatePayment(View view)
{
Intent intent = new Intent(this, paymentViewActivity.class);
EditText loanAmount = (EditText) findViewById(R.id.loanAmount);
Editable amount = loanAmount.getText();
intent.putExtra("Loan.loanAmount", Double.valueOf(amount.toString()));
EditText interestRate = (EditText) findViewById(R.id.interestRateEditText);
Editable interest = interestRate.getText();
intent.putExtra(String.valueOf(Loan.interestRate), interest);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.duration);
int selected_id = radioGroup.getCheckedRadioButtonId();
RadioButton radio_b = (RadioButton) findViewById(selected_id);
intent.putExtra(String.valueOf(Loan.loanDuration), radio_b.getText().toString());
startActivity(intent);
}
}
慕雪6442864
红颜莎娜
相关分类