MyBank3 - 增添字符串、对象数组

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lancecrazy/article/details/84612456

3 个人银行管理系统_myBank_3

3.1 改进

3.1.1 系统需求

+:: 对日期的准确表达的要求-----设计Date类

+:: 对多账户的管理-------------构造SavingsAccount对象数组

+:: 对用户名选取的范围增加-----String类的id

3.1.2 系统设计

====================================================================================================

伪代码:Date.java

目的:实现个人银行账户管理系统的日期表达

====================================================================================================

成员:
+::

  • year
  • month
  • day
  • totalDays
  • DAYS_BEFORE_MONTH[]

方法:
****+
::

  • Date(int year, int month, int day)       //构造函数
  • int getYear()
  • getMonth()
  • getDay()
  • isLeapYear()                  //判断当年是否为闰年
  • getMaxDay()                   //这个月一共多少天
  • show()                      //显示当前日期
  • distance(final Date date)            //计算相隔多少天

====================================================================================================

3.1.3 系统实现

SavingsAccount对象数组的构造

    //建立几个账户
    SavingsAccount[] accounts = new SavingsAccount[5];
    accounts[0] = new SavingsAccount(date, "S3755217", 0.015);
    accounts[1] = new SavingsAccount(date, "02342342", 0.015);

Date类构造函数

    Date(int year, int month, int day){
        if (day <= 0 || day > getMaxDay()||month>12||month<1){
            System.out.println("Invalid date: ");
            show();
            System.out.println();
            System.exit(1);
        }

        this.year = year;
        this.month = month;
        this.day = day;

        int years = year - 1;

        //计算天数
        totalDays = years * 365 + years / 4 - years / 100 + years / 400
                + DAYS_BEFORE_MONTH[month - 1] + day;

        if (isLeapYear() && month > 2) totalDays++;
    }


3.2 系统测试

2008-11-1
#S3755217 created
2008-11-1
#02342342 created
2008-11-5
#S3755217 5000.01 5000.01 salary
2008-11-25
#02342342 10000.01 10000.01 sell stock 0323
2008-12-5
#S3755217 5500.01 10500.02 salary
2008-12-20
#02342342 -3999.99 6000.02 buy a laptop

2009-1-1
#S3755217 17.77 10517.79 interest
#S3755217 Balance: 10517.79

2009-1-1
#02342342 13.2 6013.22 interest
#02342342 Balance: 6013.22

3.3 个人体会

  1. 区别
  • c++中文件的构造方式是,一个main文件,每类定义一类文件,每类实现一类文件,而java中核心思想是以构造类为核心
  • 创建类的对象一定是以**new 类名()**的形式来构造
  • java由于private和public不是分块定义,所以对每一个成员或方法都要严格的一个一个的去定义
  1. 遇到的问题
  • 对ArrayIndexOutOfBound,NullPointerException等异常的处理与抛出
  • 注释尽量简单明了

猜你喜欢

转载自blog.csdn.net/lancecrazy/article/details/84612456