javaIO流程序出现了错误,请高手详细指点!

Wangyufeng_scut Wangyufeng_scut 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是我的作业上的java代码。运行后出现了错误:

Exception in thread "main" java.io.NotSerializableException: StoreLoanObjects$Loan
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at StoreLoanObjects.main(StoreLoanObjects.java:23)import java.io.*;
代码:
public class StoreLoanObjects implements java.io.Serializable{

public StoreLoanObjects() {
// TODO Auto-generated constructor stub

}

/**
* @param args
*/
public static void main(String[] args) throws ClassNotFoundException,IOException{
// TODO Auto-generated method stub
StoreLoanObjects a = new StoreLoanObjects();

ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("Exercise19_6.dat",true));
Loan loanA = a.new Loan(2.5,4,1000);
Loan loanB = a.new Loan(2.5,2,1000);
Loan loanC = a.new Loan(2.5,4,5000);
Loan loanD = a.new Loan(6.5,4,1000);
Loan loanE = a.new Loan(6.5,2,1000);
output.writeObject(loanA);
output.writeObject(loanB);
output.writeObject(loanC);
output.writeObject(loanD);
output.writeObject(loanE);

output.close();
}

/** Loan class */
class Loan {
private double annualInterestRate;
private int numberOfYears;
private double loanAmount;
private java.util.Date loanDate;

/** Default constructor */
public Loan() {
this(2.5, 1, 1000);
}

/** Construct a loan with specified annual interest rate,
number of years and loan amount
*/
public Loan(double annualInterestRate, int numberOfYears,
double loanAmount) {
this.annualInterestRate = annualInterestRate;
this.numberOfYears = numberOfYears;
this.loanAmount = loanAmount;
loanDate = new java.util.Date();
}

/** Return annualInterestRate */
public double getAnnualInterestRate() {
return annualInterestRate;
}

/** Set a new annualInterestRate */
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}

/** Return numberOfYears */
public int getNumberOfYears() {
return numberOfYears;
}

/** Set a new numberOfYears */
public void setNumberOfYears(int numberOfYears) {
this.numberOfYears = numberOfYears;
}

/** Return loanAmount */
public double getLoanAmount() {
return loanAmount;
}

/** Set a newloanAmount */
public void setLoanAmount(double loanAmount) {
this.loanAmount = loanAmount;
}

/** Find monthly payment */
public double getMonthlyPayment() {
double monthlyInterestRate = annualInterestRate / 1200;
double monthlyPayment = loanAmount * monthlyInterestRate / (1 -
(Math.pow(1 / (1 + monthlyInterestRate), numberOfYears * 12)));
return monthlyPayment;
}

/** Find total payment */
public double getTotalPayment() {
double totalPayment = getMonthlyPayment() * numberOfYears * 12;
return totalPayment;
}

/** Return loan date */
public java.util.Date getLoanDate() {
return loanDate;
}
}

}
不知是什么问题
...全文
评论 3
收藏 已收藏
分享
返回顶部
Wangyufeng_scut
非技术区 23,404 成员 70,506 内容