我迷路了!我正在上一门在线Java课程,需要帮助完成这项任务。 一旦程序编译,它就会产生一个找不到符号的错误
Loan loan = new Loan(annualInterestRate, numberOfYears, loanAmount);
symbol: class Loan
location: class ChangeRequest5
我尝试在类ChangeRequest5中创建类Loan,以及getMonthlyPaymen的方法。该程序运行一个干净且成功的构建,并为利率,贷款期限和贷款金额创建用户输入,但不会显示该表。
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class ChangeRequest5 {
public static void main(String[] args) {
Object[] rateList = new Object[9];
int i = 0;
for (double rate = 5; rate <=6; rate += 1.0 /4)
rateList[i++] = new Double (rate);
Object annualInterestRateObject = JOptionPane.showInputDialog(
null, "Select annual interest rate:" , "Mortgage Calculator" ,
JOptionPane.QUESTION_MESSAGE, null, rateList, null);
double annualInterestRate =
((Double)annualInterestRateObject).doubleValue();
Object[]yearList = {new Integer(7), new Integer(15), new Integer(30)};
Object numberOfYearsObject = JOptionPane.showInputDialog(
null, "Select number of years:" , "Mortgage Calculator" ,
JOptionPane.QUESTION_MESSAGE, null, yearList, null);
int numberOfYears = ((Integer)numberOfYearsObject).intValue();
String loanAmountString = JOptionPane.showInputDialog(null,
"Enter loan amount, for example 200000 for $200000.00" , "Mortgage Calculator" ,
JOptionPane.QUESTION_MESSAGE);
double loanAmount = Double.parseDouble(loanAmountString);
Loan loan = new Loan(annualInterestRate, numberOfYears, loanAmount);
double monthlyPayment = loan.getMonthlyPayment();
String output = "Interest Rate:" + annualInterestRate +
"%" + "Number of Years:" + numberOfYears + " Loan Amount: $"
+ loanAmount;
output += " Monthly Payment: " + "$" + (int)(monthlyPayment * 100) /100.0;
output += " Totaly Payment $" + (int) (monthlyPayment * 12 * numberOfYears
* 100) / 100.0;
double monthlyInterestRate = annualInterestRate / 1200;
double balance = loanAmount;
double interest;
double principal;
output += " Payment#\tInterest\rPrincipal\tBalance";
for (i = 1; i <= numberOfYears * 12; i++){
interest = (int)(monthlyInterestRate * balance * 100) / 100.0;
principal = (int)((monthlyPayment - interest) * 100) / 100.0;
balance = (int)((balance - principal) * 100) / 100.0;
output += i + "\t" + interest + "\t" + principal + "\t" + balance;
}
JScrollPane jsp = new JScrollPane(new JTextArea(output));
jsp.setPreferredSize(new java.awt.Dimension(400, 200));
JOptionPane.showMessageDialog(null, jsp,
"Mortgage Calculator" , JOptionPane.INFORMATION_MESSAGE, null);
}
}
答案 0 :(得分:3)
您是否在同一个包中定义了一个类Loan.java
的文件Loan
?如果它在同一个包装中,它应该可以工作。
如果它位于不同的包中,则需要将其导入到其他.java文件中:
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import package2.Loan;
public class ChangeRequest5 {
答案 1 :(得分:1)
您需要拥有&#39;贷款&#39;的进口对帐单。除非它在同一个包中