package hello;
import java.util.Date;
public class Account {
public static void main(String[] args) {
//创建对象及初始数据
Account account1 = new Account();
account1.setId(1122);
account1.setBalance(20000);
account1.setAnnualInterestRate(4.5 / 100);
account1.withDraw(2500);
account1.deposite(3000);
System.out.println(account1.balance);
System.out.println(account1.balance * account1.annualInterestRate /12);
System.out.println(account1.dateCreated);
}
private int id = 0;
private double balance = 0, annualInterestRate = 0;
private Date dateCreated = new Date();
public Account() {
}
public Account(int newId, double newBalance) {
id = newId;
balance = newBalance;
}
//ID的访问器和修改器
public int getId() {
return id;
}
public void setId(int newId) {
id = (newId >= 0) ? newId : 0;
}
public double getBalance() {
return balance;
}
public void setBalance(double newBalance) {
balance = (newBalance >= 0) ? newBalance : 0;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double newAnnualInterestRate) {
annualInterestRate = (newAnnualInterestRate >= 0) ? newAnnualInterestRate : 0;
}
double getMonthlyIntererst(double annualInterestRate) {
return annualInterestRate / 12;
}
void withDraw(double withDraw) {
balance -= withDraw;
}
void deposite(double deposite) {
balance += deposite;
}
}
9.7(账户类Account)
猜你喜欢
转载自blog.csdn.net/weixin_39596963/article/details/79519353
今日推荐
周排行