image.png

    1. package com.atguigu.exercise2;
    2. public class Account {
    3. //属性
    4. private int id;
    5. private String pwd = "000000";//密码
    6. private double balance;//余额
    7. private static double interestRate;//利率
    8. private static double minMoney = 1.0;//最小余额
    9. private static int init = 1001;//用于自动生成id使用的
    10. //构造器
    11. public Account(){
    12. id = init++;
    13. }
    14. public Account(String pwd,double balance){
    15. id = init++;
    16. this.pwd = pwd;
    17. this.balance = balance;
    18. }
    19. //方法
    20. public String getPwd() {
    21. return pwd;
    22. }
    23. public void setPwd(String pwd) {
    24. this.pwd = pwd;
    25. }
    26. public static double getInterestRate() {
    27. return interestRate;
    28. }
    29. public static void setInterestRate(double interestRate) {
    30. Account.interestRate = interestRate;
    31. }
    32. public static double getMinMoney() {
    33. return minMoney;
    34. }
    35. public static void setMinMoney(double minMoney) {
    36. Account.minMoney = minMoney;
    37. }
    38. public int getId() {
    39. return id;
    40. }
    41. public double getBalance() {
    42. return balance;
    43. }
    44. @Override
    45. public String toString() {
    46. return "Account [id=" + id + ", pwd=" + pwd + ", balance=" + balance + "]";
    47. }
    48. }

    1. package com.atguigu.exercise2;
    2. public class AccountTest {
    3. public static void main(String[] args) {
    4. Account acct1 = new Account();
    5. Account acct2 = new Account("qwerty",2000);
    6. System.out.println(acct1);
    7. System.out.println(acct2);
    8. }
    9. }