码迷,mamicode.com
首页 > 其他好文 > 详细

交易记录

时间:2018-04-06 19:32:48      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:str   block   log   with   manage   test   code   io流   查询   

package com.lanqiao.dmeo5;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.Scanner;

public class TransRecordManager {
    private TransRecord[] records;

    Scanner sc = new Scanner(System.in);

    public void show() {
        System.out.println("=====交易记录管理系统=====");
        System.out.println("1.加载数据");
        System.out.println("2.");
        System.out.println("3.查询记录(1.根据客户号,2.根据日期)");
        System.out.println("4.总金额为");

        System.out.println("请选择:");
        int choice = sc.nextInt();
        switch (choice) {
        case 1:

            break;
        case 2:

            break;

        case 3:

            break;
        case 4:

            break;

        default:
            break;
        }
    }

    /**
     * 加载数据
     * 
     * @param in
     *            - 数据流
     * @return
     * @throws -
     *             解析过程中IO错误
     */
    public void load(InputStream in) throws IOException {
        String str = null;
        String[] strs = null;
        try {
            TransRecord tR = null;
            InputStreamReader input = new InputStreamReader(in);
            BufferedReader bfr = new BufferedReader(input);
            for (int i = 0; (str = bfr.readLine()) != null; i++) {
                if (str.startsWith("#") || str.startsWith(" ")) {
                    
                     
                    str = bfr.readLine();
                } else {
                    strs = str.split("[|]");
                    //赋值客户编号
                    tR.setCustomerNumber(strs[0]);
                    tR.getCustomerNumber();

                    tR.setCustomerName(strs[1]);
                    tR.getCustomerName();

                    tR.setInstitutionNum(strs[2]);
                    tR.getInstitutionNum();

                    tR.setSex(Integer.parseInt(strs[3]));
                    tR.getSex();

                    tR.setAccountNumber(strs[4]);
                    tR.getAccountNumber();

                    tR.setHappenTime(strs[5]);
                    tR.getHappenTime();

                    tR.setAmount(new BigDecimal(strs[6]));
                    tR.getAmount();

                    records[i] = tR;
                    System.out.println(tR.toString());

                }
            }
            bfr.close();

        } catch (IOException e) {
            System.out.println("捕获信息异常");
        }
    }

    /**
     * 加载数据
     * 
     * @param fileName
     *            - 包含记录数据的文件名
     * @return
     * @throws -
     *             解析过程中IO错误
     */
    public void load(String fileName) throws IOException {
        try {
            // 创建输入流
            FileInputStream fI = new FileInputStream(fileName);
            load(fI);
            // 关闭流
            fI.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.out.print("获取IO流信息异常!");
        }

    }

    /**
     * 取所有记录
     * 
     * @return 所有记录数组或null
     */
    public TransRecord[] getAll() {
        return records;
    }

    /**
     * 按客户号查询记录
     * 
     * @param customerNumber
     *            - 客户号
     * @return 符合条件的记录数组或null
     */
    public TransRecord[] findByCustomerNumber(String customerNumber) {
        return records;

    }

    /**
     * 按日期段查询记录
     * 
     * @param start
     *            - 开始日期
     * @param end
     *            - 结束日期
     * @return 符合条件的记录数组或null
     */
    public TransRecord[] findByDate(String start, String end) {
        return records;

    }

    /**
     * 取得总金额
     * 
     * @return 总金额
     */
    public BigDecimal totalAmount() {
        return null;

    }

    /**
     * 按金额排序
     * 
     * @return 按金额升序排序的结果
     */
    public TransRecord[] sortByAmount() {
        return records;

    }

    /**
     * 打印
     * 
     * @param out
     *            - 输出流
     */
    public void print(OutputStream out) {

    }

}
package com.lanqiao.dmeo5;

import java.math.BigDecimal;

public class TransRecord {
    private String customerNumber;//客户号
    private String customerName;//客户名
    private String institutionNum;//所属机构
    
    private int sex;//性别
    private static final String[] SEX = {"女","男"};
    
    private String accountNumber;//账号
    private String happenTime;//发生时间
    private BigDecimal amount;//发生额
    
    //get set方法
    public String getCustomerName() {
        return customerName;
    }
    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }
    public String getCustomerNumber() {
        return customerNumber;
    }
    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }
    public String getInstitutionNum() {
        return institutionNum;
    }
    public void setInstitutionNum(String institutionNum) {
        this.institutionNum = institutionNum;
    }
    public String getAccountNumber() {
        return accountNumber;
    }
    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }
    public String getHappenTime() {
        return happenTime;
    }
    public void setHappenTime(String happenTime) {
        this.happenTime = happenTime;
    }
    
    public void setSex(int sex) {
        this.sex = sex;
    }
    public BigDecimal getAmount() {
        return amount;
    }
    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }
    public static String[] getSex() {
        return SEX;
    }
    
    
    
    //重写toString方法
    public String toString() {
        return "TransRecord [customerName=" + customerName + ", customerNumber=" + customerNumber + ", institutionNum="
                + institutionNum + ", accountNumber=" + accountNumber + ", happenTime=" + happenTime + ", sex=" + sex
                + ", amount=" + amount + "]";
    } 
    
    
    
    
}
package com.lanqiao.dmeo5;

import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        TransRecordManager t = new TransRecordManager();
        
        try {
            t.load(System.getProperty("usr.dir")+"~/Java/src");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

交易记录

标签:str   block   log   with   manage   test   code   io流   查询   

原文地址:https://www.cnblogs.com/qichunlin/p/8728479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!