银行账户类:
public class Bank {
//账号 密码 存款余额 利率 最小余额 账号要自动生成
//账户
private int accountNum;
//密码
private String password;
//余额
private double balance;
//利率一般设为静态的 所用用户都是一样的利率
public static double rate = 0.1;
//最小余额
public static double minibalance = 10.0;
//用静态变量定义银行第一个账户 以便接下来无参构造的账号自动生成
public static int bankNum = 2010601212;
//每个银行账户的初始密码
public static String inipassword = "000000";
//无参构造初始化账号
public Bank(){
//自动生成账号
//每通过无参构造方法构造一个银行账户 他就会自动生成一个新的银行账户
//进而实现账号自动生成
accountNum = bankNum;
System.out.println("账号为:"+accountNum);
bankNum++;
//初始密码
password = inipassword;
System.out.println("初始密码:"+inipassword);
}
public int getNum() {
return accountNum;
}
public void setNum(int num) {
this.accountNum = num;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
@Override
public String toString() {
return "Bank{" +
"num=" + accountNum +
", password=" + password +
", balance=" + balance +
'}';
}
}
测试类:
public class BankTest {
public static void main(String[] args) {
//账户构造的同时 会输出银行账户的信息
Bank a1 = new Bank();
Bank a2 = new Bank();
Bank a3 = new Bank();
System.out.println("您的余额为:"+a1.getBalance());
System.out.println("您的余额为:"+a2.getBalance());
System.out.println("您的余额为:"+a3.getBalance());
System.out.println("银行利率为:"+Bank.rate);
System.out.println("最小余额为:"+Bank.minibalance);
}
}