Java记账系统

    选择打赏方式

简单写一个记账系统,这个系统本身并不难,用来练手的,所以仅仅只是实现了内存层面的记账功能,数据保存在内存当中,如果想要长时间的保存数据可以使用IO流来存储数据,这个系统的逻辑并不严谨,还有很多可以改善的地方,因为是练手的,所以就没考虑那么多,这些点做到心中有数即可

Main类

public class Main {
    public static void main(String[] args) {
        Menu.menu();
    }
}

Menu类

package com.main;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Menu {
    static List<Bills> list = new ArrayList<Bills>();
    static{
        list.add(new Bills(1,"安居客发","时代峰峻","sfs",1000.0,"2021.0.0","wfhw"));
    }
    public static void menu(){
        boolean flag =true;
        Scanner scanner = new Scanner(System.in);
        while(flag) {
            Shoumenu.showMenu();
            int num = scanner.nextInt();
            switch (num) {
                case 1:
                    AddBell.addBell(list);
                    break;
                case 2:
                    Delete.delete(list);
                    break;
                case 3:
                    Select.select(list);
                    break;
                case 4:
                    System.out.println("退出系统");
                    flag = false;
                    break;
                default :
                    System.out.println("请重新输入");
                    break;
            }
        }
    }
}

AddBell类

package com.main;

import java.util.List;
import java.util.Scanner;

public class AddBell {
    public static void addBell(List<Bills> list){
        System.out.println("请输入id");
        Scanner scanner = new Scanner(System.in);
        int id = scanner.nextInt();
        System.out.println("请输入name");
        String name = scanner.next();
        System.out.println("请输入account");
        String account = scanner.next();
        System.out.println("请输入type");
        String type = scanner.next();
        System.out.println("请输入amount");
        double amount = scanner.nextDouble();
        System.out.println("请输入time");
        String time = scanner.next();
        System.out.println("请输入descrip");
        String descrip = scanner.next();
        list.add(new Bills(id,name,account,type,amount,time,descrip));
        System.out.println("添加成功");
    }
}

Bills类

package com.main;

/**
 * @author ruolifeng
 */
public class Bills {
    private int id;
    private String name;
    private String account;
    private String type;
    private double amount;
    private String time;
    private String describe;

    public Bills() {
    }

    public Bills(int id, String name, String account, String type, double amount, String time, String describe) {
        this.id = id;
        this.name = name;
        this.account = account;
        this.type = type;
        this.amount = amount;
        this.time = time;
        this.describe = describe;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }
}

Delete类

package com.main;

import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Delete {
    public static void delete(List<Bills> list){
        System.out.println("请输入需要删除的数据ID");
        Scanner scanner = new Scanner(System.in);
        int id = scanner.nextInt();
        Iterator<Bills> it = list.iterator();
        while (it.hasNext()){
            Bills b = it.next();
            if(b.getId() == id){
                list.remove(b);
            }
        }
        System.out.println("删除数据成功");
    }
}

Print类

package com.main;

import java.util.Iterator;
import java.util.List;

/**
 * @author 18777
 */
public class Print {
    public static void print(List<Bills> billsList){
        Iterator it = billsList.iterator();
        while (it.hasNext()) {
            Bills b = (Bills) it.next();
            System.out.println(b.getId()+"\t\t"+b.getName()+"\t\t"+b.getAccount()+"\t\t"+b.getType()+
                    "\t\t"+b.getAmount()+"\t\t\t"+b.getTime()+"\t\t\t"+b.getDescribe());
        }
    }
}

PrintMenu类

package com.main;

public class PrintMenu {
    public static void printMenu(){
        System.out.println("ID\t\t名字\t\t账户\t\t类型\t\t金额\t\t\t时间\t\t\t备注");
    }

}

Select类

package com.main;

import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Select {
    public static void select(List<Bills> list){
        boolean flag = true;
        Scanner scanner = new Scanner(System.in);
        while (flag){
            System.out.println("1.查询所有 2.按照时间查询 3.收入和支出 4.返回上一级");
            int num = scanner.nextInt();
            switch(num){
                case 1:
                    selectAll(list);
                    break;
                case 2:
                    selectTimes(list);
                    break;
                case 3:
                    selectBuyType(list);
                    break;
                case 4:
                    flag = false;
                    break;
                default:
                    System.out.println("输入错误,请重新输入");
                    break;
            }
        }
    }
    public static void selectAll(List<Bills> list){
        PrintMenu.printMenu();
        Print.print(list);
    }
    public static void selectTimes(List<Bills> list){
        System.out.println("请输入日期:2020-1-10");
        Scanner scanner = new Scanner(System.in);
        String num = scanner.next();
        PrintMenu.printMenu();
        List<Bills> billsList = list.stream().filter(lists -> {
            String type = lists.getTime();
            return type.equals(num);
        }).collect(Collectors.toList());
        Print.print(billsList);
    }
    public static void selectBuyType(List<Bills> list){
        System.out.println("请输入支出 || 收入");
        String type;
        Scanner scanner = new Scanner(System.in);
        String num = scanner.next();
        switch(num){
            case "支出":
                type = "支出";
                buySell(list,type);
                break;
            case "收入":
                type = "收入";
                buySell(list,type);
                break;
            default:
                break;
        }
    }
    public static void buySell(List<Bills> list, String buyType){
        PrintMenu.printMenu();
        List<Bills> billsList = list.stream().filter(lists -> {
            String type = lists.getType();
            return type.equals(buyType);
        }).collect(Collectors.toList());
        Print.print(billsList);
    }
}

ShouMenu类

package com.main;

public class Shoumenu {
    public static void showMenu(){
        System.out.println("--------------记账本--------------");
        System.out.println("1.添加账务 2.删除账务 3.查询账务 4.退出系统");
        System.out.println("请输入功能序号(1-4)");
    }
}
版权声明:若无特殊注明,本文为《若离风》原创,转载请保留文章出处。
本文链接:https://www.rlfit.cn/post-55.html
正文到此结束

热门推荐

发表吐槽

你肿么看?

你还可以输入 250 / 250 个字

嘻嘻 大笑 可怜 吃惊 害羞 调皮 鄙视 示爱 大哭 开心 偷笑 嘘 奸笑 委屈 抱抱 愤怒 思考 日了狗 胜利 不高兴 阴险 乖 酷 滑稽

评论信息框
可使用QQ号实时获取昵称+头像

私密评论

吃奶的力气提交吐槽中...


既然没有吐槽,那就赶紧抢沙发吧!