图书管理系统(使用IO流实现数据的读取和写入)--version4.0

 目录

一、项目要求:

二、项目环境

三、项目使用的知识点

四、项目代码

五、项目运行结果

六、项目难点分析


图书管理系统--versions1.0:

图书管理系统--versions1.0-CSDN博客文章浏览阅读981次,点赞29次,收藏17次。本文使用了变量,数据类型,顺序,选择,循环,数组实现了一个简单的小项目--图书管理系统,其中包括用户管理,图书管理,不同权限管理的内容不同。https://blog.csdn.net/qq_53483101/article/details/135583634?spm=1001.2014.3001.5501icon-default.png?t=N7T8https://blog.csdn.net/qq_53483101/article/details/135583634?spm=1001.2014.3001.5501

图书管理系统--versions2.0:

图书管理系统--versions2.0-CSDN博客文章浏览阅读1k次,点赞35次,收藏19次。本文使用了变量,数据类型,顺序,选择,循环,数组,对象及属性的封装实现了一个简单的小项目--图书管理系统,其中包括用户管理,图书管理,不同权限管理的内容不同。https://blog.csdn.net/qq_53483101/article/details/135728923?spm=1001.2014.3001.5501icon-default.png?t=N7T8https://blog.csdn.net/qq_53483101/article/details/135728923?spm=1001.2014.3001.5501

图书管理系统--versions3.0:

图书管理系统(ArrayList和LinkedList)--versions3.0-CSDN博客本文使用了变量,数据类型,顺序,选择,循环,对象及属性的封装,使用ArrayList和LinkedList集合,实现了一个简单的小项目--图书管理系统,其中包括用户管理,图书管理,不同权限管理的内容不同。https://blog.csdn.net/qq_53483101/article/details/135939196?spm=1001.2014.3001.5501icon-default.png?t=N7T8https://blog.csdn.net/qq_53483101/article/details/135939196?spm=1001.2014.3001.5501

 图书管理系统--versions4.0:图书管理系统(使用IO流实现数据的读取和写入)--version4.0-CSDN博客文章浏览阅读342次,点赞8次,收藏9次。使用io实现图书管理系统中管理员用户、普通用户、书籍信息的读取和写入。https://blog.csdn.net/qq_53483101/article/details/136306379?spm=1001.2014.3001.5501


一、项目要求:

1)通过账号控制图书管理系统,账号分为管理员账号和普通用户账号
    1. 管理员账号和普通用户账号都可以使用手机号码+密码、身份证号码+密码的形式登录,登录方式二选一

     2.管理员账号和普通账号除了手机号码、身份中号码、密码三个数据之外,还有姓名、性别、专业、住址信息

2)启动系统后,显示登录账号、注册账号、退出登录三个模块
        a)登录账号:
                1、显示管理员登录
                2、用户登录两个模块

        b)注册账号:
                1、显示注册管理员
                2、注册用户两个模块
        c)退出登录:

        结束程序运行

3)登录账号成功后,根据账号的性质来显示不同的模块:
        登录管理员账号成功后,显示如下模块:

                1、查看所有图书,图书显示哪些信息,这里设计的信息有书名,书的价格,书的数量

                2、添加图书

                3、修改图书 

                4、删除图书

                5、查看所有普通用户信息

                6、查看管理员账号信息

                7、修改管理员账号信息

                8、退出系统

        登录普通账号成功后,显示如下模块:

                1、查看所有图书,图书显示哪些信息,你自行设计

                2、借阅图书

                3、归还图书

                4、显示用户信息(只能查看自己的用户信息)

                5、修改用户信息(只能修改自己的用户信息)

                6、退出系统

4)使用对象对不同类及其各自属性进行封装与功能实现

5)使用IO流实现数据的读取和写入

二、项目环境

(1)开发工具:IDEA、JDK17
(2)开发语言:Java

三、项目使用的知识点

(1)理解程序基本概念——程序、变量、数据类型
(2)顺序、选择、循环、跳转语句

(3)使用对象的思想对图书管理系统--versions1.0进行改造

        这里使用了对象封装的思想,将其分为管理员用户类,普通用户,书类,工具类,系统主页面类,将各自的类的属性功能封装,在系统页面类里面调用这些属性方法实现各个功能的开发。

   (4)使用io流实现了数据的读取和写入。

四、项目代码

        这里说明一下,为了快速写出项目,前面的用户管理的八个属性均采用String类型存储,方便自己后续代码的编写及相关功能的实现,有不足或者想要自己实现的功能部分读者可以自行修改代码实现。

AdminUser类:
package com.iosystem;

import java.io.*;

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

public class AdminUser {
    private String adminUser;  //0
    private String adminPhoneNumber;  // 1
    private String adminIdentityNumber;  //2
    private String adminPassword;  //3
    private String adminName;
    private String adminSex;
    private String adminCareer;
    private String adminAddress;


    public AdminUser() {
    }

    public AdminUser(String adminUser, String adminPhoneNumber, String adminIdentityNumber, String adminPassword, String adminName, String adminSex, String adminCareer, String adminAddress) {
        this.adminUser = adminUser;
        this.adminPhoneNumber = adminPhoneNumber;
        this.adminIdentityNumber = adminIdentityNumber;
        this.adminPassword = adminPassword;
        this.adminName = adminName;
        this.adminSex = adminSex;
        this.adminCareer = adminCareer;
        this.adminAddress = adminAddress;
    }

    public String getAdminUser() {
        return adminUser;
    }

    public void setAdminUser(String adminUser) {
        this.adminUser = adminUser;
    }

    public String getAdminPhoneNumber() {
        return adminPhoneNumber;
    }

    public void setAdminPhoneNumber(String adminPhoneNumber) {
        this.adminPhoneNumber = adminPhoneNumber;
    }

    public String getAdminIdentityNumber() {
        return adminIdentityNumber;
    }

    public void setAdminIdentityNumber(String adminIdentityNumber) {
        this.adminIdentityNumber = adminIdentityNumber;
    }

    public String getAdminPassword() {
        return adminPassword;
    }

    public void setAdminPassword(String adminPassword) {
        this.adminPassword = adminPassword;
    }

    public String getAdminName() {
        return adminName;
    }

    public void setAdminName(String adminName) {
        this.adminName = adminName;
    }

    public String getAdminSex() {
        return adminSex;
    }

    public void setAdminSex(String adminSex) {
        this.adminSex = adminSex;
    }

    public String getAdminCareer() {
        return adminCareer;
    }

    public void setAdminCareer(String adminCareer) {
        this.adminCareer = adminCareer;
    }

    public String getAdminAddress() {
        return adminAddress;
    }

    public void setAdminAddress(String adminAddress) {
        this.adminAddress = adminAddress;
    }



    Scanner scan = new Scanner(System.in);
    //管理员用户登录验证
    public int loginCheck(File file) throws IOException {
        BufferedReader brd = new BufferedReader(new FileReader(file));

        System.out.print("请输入你要登录的形式(1.手机号码+密码 2.身份证号码+密码):");
        int verifyNum = scan.nextInt();  //verifyNum  验证方式数字
        //只能选择一种登录方式
        while (true) {
            if (verifyNum == 1 || verifyNum == 2) {
                break;
            } else {
                System.out.print("\n输入错误,请输入要选择要操作的序号(只能输入1,2):");
                verifyNum = scan.nextInt();
            }
        }
        //   1.手机号码+密码   2.身份证号码+密码
        System.out.print("请输入你要登录的管理员序号(0,1,2):");
        int adminId = scan.nextInt();  //  登录管理员账号序号
        ArrayList<String> lines = new ArrayList<>();

        String line;
        while((line=brd.readLine())!=null){
            lines.add(line);
        }

        int x = lines.size();
        while(true){
            if(adminId<=x-1){
                break;
            }else {
                System.out.print("你输入的管理员账户不存在,请重新输入你要登录的管理员序号(0,1,2):");
                adminId = scan.nextInt();  //  登录管理员账号序号
            }

        }

        String[] strings = lines.get(adminId).split(",");
        if (verifyNum == 1) {    // 管理员用户
            //  管理员登录验证     手机号码+密码
            System.out.println("\n---请输入你的验证信息---");
            System.out.print("\n请输入管理员账号(默认root):");
            String adminUser1 = scan.next();
            System.out.print("\n请输入手机号码");
            String adminPhoneNumber1 = scan.next();
            System.out.print("\n请输入密码:");
            String adminPassword1 = scan.next();

            while (true) {
                if (adminUser1.equals(strings[0]) && adminPhoneNumber1.equals(strings[1]) && adminPassword1.equals(strings[3])) {
                    break;
                } else {
                    System.out.println("输入信息错误,请重新输入信息!");
                    System.out.print("请输入管理员账号序号(默认root):");
                    adminUser1 = scan.next();
                    System.out.print("\n请输入手机号码:");
                    adminPhoneNumber1 = scan.next();
                    System.out.print("\n请输入密码:");
                    adminPassword1 = scan.next();
                }
            }
        } else if (verifyNum == 2) {   //  管理员登录验证     身份证号码+密码
            System.out.print("请输入账号(默认root):");
            String adminUser2 = scan.next();
            System.out.print("\n请输入身份证号码:");
            String adminIdentityNumber2 = scan.next();
            System.out.print("\n请输入密码:");
            String adminPassword2 = scan.next();
            while (true) {
                if (adminUser2.equals(strings[0]) && adminIdentityNumber2.equals(strings[2]) && adminPassword2.equals(strings[3])) {
                    break;
                } else {
                    System.out.println("输入信息错误,请重新输入信息!");
                    System.out.print("请输入账号(默认root):");
                    adminUser2 = scan.next();
                    System.out.print("\n请输入身份证号码:");
                    adminIdentityNumber2 = scan.next();
                    System.out.print("\n请输入密码:");
                    adminPassword2 = scan.next();
                }
            }
        }
        System.out.println("登录成功!");
        brd.close();
        return adminId;
    }
    // 注册管理员用户
    public void addAdminUser(File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
        ArrayList<String> lines = new ArrayList<String>();
        String line=null;
        while((line = bufferedReader.readLine())!=null){
            lines.add(line);
        }
        System.out.print("\n请输入新的管理员账户名:");
        String user = scan.next();
        System.out.print("\n请输入新的手机号码:");
        String phonenumber = scan.next();
        System.out.print("\n请输入新的身份证号码:");
        String identitynumber = scan.next();
        System.out.print("\n请输入新的密码:");
        String password = scan.next();
        System.out.print("\n请输入新的姓名:");
        String name = scan.next();
        System.out.print("\n请输入新的性别:");
        String sex= scan.next();
        System.out.print("\n请输入新的专业:");
        String career= scan.next();
        System.out.print("\n请输入新的住址信息:");
        String address = scan.next();
        line =user  +","+ phonenumber +","+ identitynumber+","
                    +password+"," +name+"," + sex+","
                    +career+"," + address;

        lines.add(line);
        BufferedWriter bf = new BufferedWriter(new FileWriter(file));

        for (String content :lines){
            bf.write(content);
            bf.newLine();
        }
        System.out.println("注册管理员用户成功!");
        bf.flush();
        bf.close();
        bufferedReader.close();
    }

    //查看管理员账号信息
    public void adminInfo(File file) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(file));

        System.out.println("序号\t\t\t"+"账户名\t\t\t"+"手机号\t\t\t"+"身份证号\t\t\t"+"密码\t\t\t"+"姓名\t\t\t"+"性别\t\t\t"+"专业\t\t\t"+"住址\t\t\t");
        String line;
        int count =0;
        while ((line=br.readLine())!=null){
            String[] strings = line.split(",");
            System.out.print(count++ +"\t\t\t");
            for(int i=0;i<strings.length;i++){
                System.out.print(strings[i]+"\t\t\t");
            }
            System.out.print("\n");
        }
        br.close();
    }
    //修改管理员账号信息
    // num 修改信息序号  id 登录的是第几个管理员
    public void adminAlter(int num, int id, File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        ArrayList<String> strb = new ArrayList<String>();
        String line =null;
        int count=0;
        while((line=bufferedReader.readLine())!=null){
            if(count==id){
                String[] strings = line.split(",");
                if (num == 1) {                  // 管理员账号名
                    System.out.print("\n请输入新的管理员账户名:");
                    String user = scan.next();
                    strings[0] = user;
                    line = String.join(",",strings);
                    strb.add(line);

                } else if (num == 2) {        // 手机号码
                    System.out.print("\n请输入新的手机号码:");
                    String phonenumber = scan.next();
                    strings[1] = phonenumber;
                    line = String.join(",",strings);
                    strb.add(line);
                } else if (num == 3) {        // 身份证号码
                    System.out.print("\n请输入新的身份证号码:");
                    String identitynumber = scan.next();
                    strings[2] = identitynumber;
                    line = String.join(",",strings);
                    strb.add(line);
                } else if (num == 4) {        // 密码
                    System.out.print("\n请输入新的密码:");
                    String password = scan.next();
                    strings[3] = password;
                    line = String.join(",",strings);
                    strb.add(line);
                } else if (num == 5) {        // 姓名
                    System.out.print("\n请输入新的姓名:");
                    String name = scan.next();
                    strings[4] = name;
                    line = String.join(",",strings);
                    strb.add(line);
                } else if (num == 6) {        // 性别
                    System.out.print("\n请输入新的性别:");
                    String sex = scan.next();
                    strings[5] = sex;
                    line = String.join(",",strings);
                    strb.add(line);
                } else if (num == 7) {        // 专业
                    System.out.print("\n请输入新的专业:");
                    String career = scan.next();
                    strings[6] = career;
                    line = String.join(",",strings);
                    strb.add(line);
                } else if (num == 8) {        // 住址信息
                    System.out.print("\n请输入新的住址信息:");
                    String address = scan.next();
                    strings[7] = address;
                    line = String.join(",",strings);
                    strb.add(line);
                }
                System.out.println("修改成功!");
            }else {
                strb.add(line);
            }
            count++;
        }

        BufferedWriter bf = new BufferedWriter(new FileWriter(file));
        for(String info:strb){
            bf.write(info);
            bf.newLine();
        }
        bf.flush();
        bf.close();
        bufferedReader.close();
    }
}
NormalUser类:
package com.iosystem;

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class NormalUser {
    private String normalUser;
    private String normalPhoneNumber;
    private String normalIdentityNumber;
    private String normalPassword;
    private String normalName;
    private String normalSex;
    private String normalCareer;
    private String normalAddress;

    Scanner scan = new Scanner(System.in);


    public NormalUser() {

    }

    public NormalUser(String normalUser, String normalPhoneNumber, String normalIdentityNumber, String normalPassword, String normalName, String normalSex, String normalCareer, String normalAddress) {
        this.normalUser = normalUser;
        this.normalPhoneNumber = normalPhoneNumber;
        this.normalIdentityNumber = normalIdentityNumber;
        this.normalPassword = normalPassword;
        this.normalName = normalName;
        this.normalSex = normalSex;
        this.normalCareer = normalCareer;
        this.normalAddress = normalAddress;
    }

    public String getNormalUser() {
        return normalUser;
    }

    public void setNormalUser(String normalUser) {
        this.normalUser = normalUser;
    }

    public String getNormalPhoneNumber() {
        return normalPhoneNumber;
    }

    public void setNormalPhoneNumber(String normalPhoneNumber) {
        this.normalPhoneNumber = normalPhoneNumber;
    }

    public String getNormalIdentityNumber() {
        return normalIdentityNumber;
    }

    public void setNormalIdentityNumber(String normalIdentityNumber) {
        this.normalIdentityNumber = normalIdentityNumber;
    }

    public String getNormalPassword() {
        return normalPassword;
    }

    public void setNormalPassword(String normalPassword) {
        this.normalPassword = normalPassword;
    }

    public String getNormalName() {
        return normalName;
    }

    public void setNormalName(String normalName) {
        this.normalName = normalName;
    }

    public String getNormalSex() {
        return normalSex;
    }

    public void setNormalSex(String normalSex) {
        this.normalSex = normalSex;
    }

    public String getNormalCareer() {
        return normalCareer;
    }

    public void setNormalCareer(String normalCareer) {
        this.normalCareer = normalCareer;
    }

    public String getNormalAddress() {
        return normalAddress;
    }

    public void setNormalAddress(String normalAddress) {
        this.normalAddress = normalAddress;
    }





    // 验证普通用户登录
    public int loginCheck(File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        //  普通用户登录验证
        System.out.print("请输入你要登录的形式(1.手机号码+密码 2.身份证号码+密码):");
        int verifyNum = scan.nextInt();  //verifyNum  验证方式数字
        //只能选择一种登录方式
        while (true) {
            if (verifyNum == 1 || verifyNum == 2) {
                break;
            } else {
                System.out.print("\n输入错误,请重新输入要选择要操作的序号(只能输入1,2):");
                verifyNum = scan.nextInt();
            }
        }
        System.out.print("请输入你要登录的普通用户序号(0,1,2,3...):");
        int normalID = scan.nextInt();  //  登录普通用户账号序号
        ArrayList<String> lines = new ArrayList();

        String line ;
        while((line=bufferedReader.readLine())!=null){
            lines.add(line);
        }
        int x = lines.size();
        //   1.手机号码+密码   2.身份证号码+密码
        while(true){
            if(normalID<=x-1){
                break;
            }else {
                System.out.print("你输入的管理员账户不存在,请重新输入你要登录的普通用户序号(0,1,2,3...):");
                normalID = scan.nextInt();  //  登录管理员账号序号
            }

        }
        String[] strings = lines.get(normalID).split(",");
        if (verifyNum == 1) {    // 普通用户
            //  普通用户登录验证     手机号码+密码
            System.out.print("\n请输入管理员账号(默认normal):");
            String normalUser1 = scan.next();
            System.out.print("\n请输入手机号码");
            String normalPhoneNumber1 = scan.next();
            System.out.print("\n请输入密码:");
            String normalPassword1 = scan.next();
            while (true) {
                if (normalUser1.equals(strings[0]) && normalPhoneNumber1.equals(strings[1]) && normalPassword1.equals(strings[3])) {
                    break;
                } else {
                    System.out.println("输入信息错误,请重新输入!");
                    System.out.print("\n请输入管理员账号序号(默认normal):");
                    normalUser1 = scan.next();
                    System.out.print("\n请输入手机号码:");
                    normalPhoneNumber1 = scan.next();
                    System.out.print("\n请输入密码:");
                    normalPassword1 = scan.next();
                }
            }
        } else if (verifyNum == 2) {   //  普通用户登录验证     身份证号码+密码
            System.out.print("\n请输入账号(默认normal):");
            String normalUser2 = scan.next();
            System.out.print("\n请输入身份证号码:");
            String normalIdentityNumber2 = scan.next();
            System.out.print("\n请输入密码:");
            String normalPassword2 = scan.next();
            while (true) {
                if (normalUser2.equals(strings[0]) && normalIdentityNumber2.equals(strings[2]) && normalPassword2.equals(strings[3])) {
                    break;
                } else {
                    System.out.println("输入信息错误,请重新输入!");
                    System.out.print("\n请输入账号:");
                    normalUser2 = scan.next();
                    System.out.print("\n请输入身份证号码:");
                    normalIdentityNumber2 = scan.next();
                    System.out.print("\n请输入密码:");
                    normalPassword2 = scan.next();
                }
            }
        }
        System.out.println("登录成功!");
        bufferedReader.close();

        return normalID;
    }

    // 注册普通用户
    public void addNormalUser(File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        ArrayList<String> strb = new ArrayList<>();
        String line=null;
        while((line = bufferedReader.readLine())!=null){
            strb.add(line);
        }
        System.out.print("\n请输入新的用户账户名:");
        String user = scan.next();

        System.out.print("\n请输入新的手机号码:");
        String phonenumber = scan.next();

        System.out.print("\n请输入新的身份证号码:");
        String identitynumber = scan.next();

        System.out.print("\n请输入新的密码:");
        String password = scan.next();

        System.out.print("\n请输入新的姓名:");
        String name = scan.next();

        System.out.print("\n请输入新的性别:");
        String sex= scan.next();

        System.out.print("\n请输入新的专业:");
        String career= scan.next();

        System.out.print("\n请输入新的住址信息:");
        String address = scan.next();

        String addString =user+","+phonenumber+","+identitynumber+","
                    +password+","+name+","+sex+","
                    +","+career+","+address;
        strb.add(addString);
        BufferedWriter bw = new BufferedWriter(new FileWriter(file));

        for(String info:strb){
            bw.write(info);
            bw.newLine();
        }
        System.out.println("注册成功!");
        bw.flush();
        bw.close();
        bufferedReader.close();

    }

    // 查看所有普通用户信息

    public void allNormal(File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        System.out.println("所有普通用户信息如下:");
        System.out.println("序号\t\t\t"+"账户名\t\t\t"+"手机号\t\t\t"+"身份证号\t\t\t"+"密码\t\t\t"+"姓名\t\t\t"+"性别\t\t\t"+"专业\t\t\t"+"住址\t\t\t");

        String line = null;
        String[] strings = null;  // 存储一条用户信息
       for(int i=0;(line=bufferedReader.readLine())!=null;i++){
            strings = line.split(",");
           if (line != "\n") {
               System.out.print(i +"\t\t\t");
           }
            for(int j=0;j<strings.length;j++){
                System.out.print(strings[j]+"\t\t\t");
            }
           System.out.print("\n");
        }
        bufferedReader.close();
    }
    // 修改用户信息
    // num 修改信息序号  id 登录的是第几个管理员
    public void normalAlter(int num,int normalid,File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
        ArrayList<String> strb = new ArrayList<>();
        String line =null;
        int count=0;
        while((line=bufferedReader.readLine())!=null){
            if(count==normalid){
                String[] strings = line.split(",");
                if(num ==1){                  // 管理员账号名
                    System.out.print("\n请输入新的管理员账户名:");
                    String user = scan.next();
                    strings[0] = user;
                } else if (num ==2) {        // 手机号码
                    System.out.print("\n请输入新的手机号码:");
                    String phonenumber = scan.next();
                    strings[1]=phonenumber;
                } else if (num ==3) {        // 身份证号码
                    System.out.print("\n请输入新的身份证号码:");
                    String identitynumber = scan.next();
                    strings[2] = identitynumber;
                } else if (num ==4) {        // 密码
                    System.out.print("\n请输入新的密码:");
                    String password = scan.next();
                    strings[3] = password;
                } else if (num ==5) {        // 姓名
                    System.out.print("\n请输入新的姓名:");
                    String name = scan.next();
                    strings[4]=name;
                } else if (num ==6) {        // 性别
                    System.out.print("\n请输入新的性别:");
                    String sex= scan.next();
                    strings[5] = sex;
                } else if (num ==7) {        // 专业
                    System.out.print("\n请输入新的专业:");
                    String career= scan.next();
                    strings[6] = career;
                } else if (num ==8) {        // 住址信息
                    System.out.print("\n请输入新的住址信息:");
                    String address = scan.next();
                    strings[7] = address;
                }
                line = String.join(",", strings);
                strb.add(line);
                System.out.println("修改成功");
            }else {
                strb.add(line);
            }
            count++;
        }
        BufferedWriter bw = new BufferedWriter(new FileWriter(file));
        for(String info: strb){
            bw.write(info);
            bw.newLine();
        }
        bw.flush();
        bw.close();
        bufferedReader.close();
    }
    // 显示用户信息(只能查看自己的用户信息)
    public void myInformation(int normalId,File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
        String line=null;
        System.out.println("个人信息如下:");
        System.out.println("账户名\t\t\t"+"手机号\t\t\t"+"身份证号\t\t\t"+"密码\t\t\t"+"姓名\t\t\t"+"性别\t\t\t"+"专业\t\t\t"+"住址\t\t\t");
        int count=0;
        while((line = bufferedReader.readLine())!=null){
            if(count==normalId){
                String[] strings = line.split(",");
                for(int j=0;j<strings.length;j++){
                    System.out.print(strings[j]+"\t\t\t");
                }
                System.out.print("\n");
            }
            count++;
        }
        System.out.println("查看结束");
        bufferedReader.close();
    }


}
Book类:
package com.iosystem;

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Book {
    private String bookName;
    private String bookPrice;
    private String bookNum;


    Scanner scan = new Scanner(System.in);


    public Book() {

    }

    public Book(String bookName, String bookPrice, String bookNum) {
        this.bookName = bookName;
        this.bookPrice = bookPrice;
        this.bookNum = bookNum;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getBookPrice() {
        return bookPrice;
    }

    public void setBookPrice(String bookPrice) {
        this.bookPrice = bookPrice;
    }

    public String getBookNum() {
        return bookNum;
    }

    public void setBookNum(String bookNum) {
        this.bookNum = bookNum;
    }



    //  查看所有图书
    public void viewAllBook(File file) throws IOException {
        System.out.println("序号\t\t\t书名\t\t\t价格\t\t\t数量");
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
        String line = null;


        for(int i=0;(line=bufferedReader.readLine())!=null;i++){
            String[] strings = line.split(",");
            System.out.print(i +"\t\t\t");
            for(int j=0;j<strings.length;j++){
                System.out.print(strings[j]+"\t\t\t");
            }
            System.out.print("\n");
        }
        bufferedReader.close();
    }
    // 添加图书
    public void addBook(File file) throws IOException {
        BufferedReader bufferedReader =  new BufferedReader(new FileReader(file));

        ArrayList<String> strb = new ArrayList<>();
        System.out.print("\n请输入图书名:");
        String name = scan.next();
        System.out.print("\n请输入图书价格:");
        String price = scan.next();
        System.out.print("\n请输入图书数量:");
        String num = scan.next();

        String addBook =name+","+price+","+num;
        String line =null;
        while((line = bufferedReader.readLine())!=null){
            strb.add(line);
        }
        strb.add(addBook);
        BufferedWriter bw = new BufferedWriter(new FileWriter(file));;
        for(String info:strb){
            bw.write(info);
            bw.newLine();
        }
        bw.flush();
        bw.close();
        bufferedReader.close();
        System.out.println("添加图书成功!");
    }
    // 修改图书
    public void alterBook(File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        ArrayList<String> strb = new ArrayList<>();
        String line = null;
        int count=0;

        System.out.print("请输入修改图书序号:");
        int bookID=scan.nextInt();  //修改图书序号

        while((line = bufferedReader.readLine())!=null){
            if(count == bookID){
                String[] strings = line.split(",");
                System.out.print("\n请输入图书名:");
                String name = scan.next();
                strings[0] = name;

                System.out.print("\n请输入图书价格:");
                String price = scan.next();
                strings[1] = price;

                System.out.print("\n请输入图书数量:");
                String num = scan.next();
                strings[2] = num;

                line =String.join(",", strings);
                strb.add(line);
                System.out.println("修改图书成功!");
            }else {
                strb.add(line);
            }
            count++;
        }

        BufferedWriter bw = new BufferedWriter(new FileWriter(file));

        for(String info: strb){
            bw.write(info);
            bw.newLine();
        }
        bw.flush();
        bw.close();
        bufferedReader.close();
    }
    // delete 删除图书
    public void deleteBook(File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        ArrayList<String> strb = new ArrayList<>();
        System.out.println("请输入删除图书序号:");
        int bookID=scan.nextInt();  //修改图书序号
        String line = null;

        while((line = bufferedReader.readLine())!=null){
            strb.add(line);
        }
        int x = strb.size();
        while(true){
            if (bookID >= 0 &&bookID < x) {
                break;
            }else {
                System.out.println("输入错误,请重新输入删除图书序号:");
                bookID=scan.nextInt();  //修改图书序号
            }
        }
        // 集合中删除图书
        strb.remove(bookID);
        BufferedWriter bw = new BufferedWriter(new FileWriter(file));
        for(String info :strb){
            bw.write(info);
            bw.newLine();
        }
        System.out.println("删除图书成功!");
        bw.flush();
        bw.close();
        bufferedReader.close();
    }
    // 借阅图书
    public void borrowBook(File file) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        ArrayList<String> strb = new ArrayList<>();
        System.out.print("\n请输入你要借阅图书序号:");
        int numbook = scan.nextInt();
        String line =null;
        int count=0;
        while((line = bufferedReader.readLine())!=null){
            if(count ==numbook){
                String[] strings = line.split(",");
                System.out.print("\n该图书还有"+strings[2]+"本");
                System.out.print("\n请输入你要借的图书数量:");
                int nums = scan.nextInt();   //  借阅数量
                int bookNum =Integer.parseInt(strings[2]);
                if((bookNum-nums)>=0){
                    bookNum-=nums;
                    String strNum = String.valueOf(bookNum);
                    strings[2] = strNum;
                    line = String.join(",", strings);
                    strb.add(line);
                    System.out.print("\n恭喜你借阅成功,该图书还剩余"+bookNum+"本\n");
                }else{
                    System.out.print("\n很遗憾,该图书已经全被借阅!");
                }
            }else {
                strb.add(line);
            }
            count++;
        }

        BufferedWriter bw = new BufferedWriter(new FileWriter(file));
        for(String info : strb){
            bw.write(info);
            bw.newLine();
        }
        bw.flush();
        bw.close();
        bufferedReader.close();
    }
    // 归还图书
    public void giveBackBook(File file) throws IOException {

        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        ArrayList<String> strb = new ArrayList<>();

        System.out.print("\n请输入你要归还图书序号:");
        int bk = scan.nextInt();

        String line = null;
        int count=0;
        while((line = bufferedReader.readLine())!=null){
            if(count == bk){
                String[] strings = line.split(",");
                System.out.print("\n该图书目前剩余"+strings[2]+"本");
                System.out.print("\n请输入归还书本数目:");
                int givenum = scan.nextInt();
                int sum=Integer.parseInt(strings[2])+givenum;
                strings[2] = String.valueOf(sum);
                line = String.join(",",strings);
                strb.add(line);
                System.out.print("\n恭喜你归还成功,现剩余该图书"+sum+"本");
            }else {
                strb.add(line);
            }
            count++;
        }
        BufferedWriter bw = new BufferedWriter(new FileWriter(file));
        for (String info: strb){
            bw.write(info);
            bw.newLine();
        }
        bw.flush();
        bw.close();
        bufferedReader.close();
    }

}
Tool类:
package com.iosystem;

public class Tool {
    public void page1(){
        System.out.println("----------------请选择登录方式----------------");
        System.out.println("             1、登录账号");
        System.out.println("             2、注册账号");
        System.out.println("             3、退出登录");
    }
    public void page2(){
        System.out.println("********欢迎进入登录账号页面********");
        System.out.println("1.管理员登录:");
        System.out.println("2.普通用户登录:");
    }
    public void page3(){
        System.out.println("\n-----------欢迎进入管理员账号页面-----------");
        System.out.println("1、查看所有图书");
        System.out.println("2、添加图书");
        System.out.println("3、修改图书");
        System.out.println("4、删除图书");
        System.out.println("5、查看所有普通用户信息");
        System.out.println("6、查看管理员账号信息");
        System.out.println("7、修改管理员账号信息");
        System.out.println("8、退出系统");
    }
    public void page4(){
        System.out.println("\n-----------普通用户登录成功-----------");
        System.out.println("1.查看所有图书");
        System.out.println("2.借阅图书");
        System.out.println("3.归还图书");
        System.out.println("4.显示用户信息(只能查看自己的用户信息)");
        System.out.println("5.修改用户信息(只能修改自己的用户信息)");
        System.out.println("6.退出系统");
    }
    public void page5(){
        System.out.println("********欢迎进入注册账号页面********");
        System.out.println("1.管理员注册:");
        System.out.println("2.普通用户注册:");
    }

}
 BooksManagementSystemThree类:
package com.iosystem;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class BooksManagementSystemNew {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Tool tool = new Tool();
        AdminUser adminUser= new AdminUser();
        Book book = new Book();
        NormalUser normalUser = new NormalUser();

        File adminUL = new File("E:\\Java Code base\\FoodOrderingSystem\\src\\com\\Admin.txt");
        File bookL = new File( "E:\\Java Code base\\FoodOrderingSystem\\src\\com\\Book.txt");
        File normalUL = new File("E:\\Java Code base\\FoodOrderingSystem\\src\\com\\Normal.txt");

        while(true){
            while(true) {
                tool.page1();
                System.out.print("请输入要选择要操作的序号(只能输入1,2,3):");
                int loginNum = scan.nextInt();
                //  校验输入的序号,只能是1到3
                while (true) {
                    if (loginNum == 1 || loginNum == 2 || loginNum == 3) {
                        break;
                    } else {
                        System.out.print("请输入要选择要操作的序号(只能输入1,2,3):");
                        loginNum = scan.nextInt();
                    }
                }
                switch(loginNum){
                    case 1:
                        tool.page2();
                        System.out.print("请输入要选择要操作的序号(只能输入1,2):");
                        int enterNum =scan.nextInt();  //enterNum登录数字  1.管理员  2.用户
                        while(true){
                            if(enterNum == 1||enterNum == 2 ){
                                break;
                            }else{
                                System.out.print("输入错误,请从从新输入要选择要操作的序号(只能输入1,2):");
                                enterNum =scan.nextInt();
                            }
                        }
                        if(enterNum==1){

                            int adminID = 0;
                            try {
                                adminID = adminUser.loginCheck(adminUL);
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                            while(true) {
                                tool.page3();
                                System.out.print("请输入你选择的功能:");
                                int adminnum = scan.nextInt();  // adminnum  管理员账号页面功能查看
                                while(true){
                                    if(adminnum>=1&&adminnum<=8){
                                        break;
                                    }else{
                                        System.out.print("输入错误,请重新输入你选择的功能:");
                                        adminnum = scan.nextInt();
                                    }
                                }

                                if(adminnum ==1){               //1、查看所有图书
                                    try {
                                        book.viewAllBook(bookL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;
                                } else if (adminnum==2) {      //2、添加图书
                                    try {
                                        book.addBook(bookL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;

                                } else if (adminnum==3) {    //3、修改图书      //这里设计的是符合图书序号的所有图书信息都可以修改
                                    try {
                                        book.alterBook(bookL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;

                                } else if (adminnum==4) {    //4、删除图书
                                    try {
                                        book.deleteBook(bookL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;
                                } else if (adminnum==5) {    //5、查看所有普通用户信息
                                    try {
                                        normalUser.allNormal(normalUL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;

                                } else if (adminnum==6) {    //6、查看管理员账号信息
                                    try {
                                        adminUser.adminInfo(adminUL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;
                                } else if (adminnum==7) {    //7、修改管理员账号信息
                                    System.out.println("请输入要修改管理员账号的的信息(1管理员账号名2手机号码3" +
                                            "身份证号码4密码5姓名6性别7专业8住址信息):");
                                    int adID =scan.nextInt();   // adID  修改序号
                                    try {
                                        adminUser.adminAlter(adID, adminID,adminUL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;
                                }else if (adminnum==8){      //8、退出系统
                                    System.out.println("谢谢使用,欢迎下次光临!");
                                    System.exit(0);;
                                }
                            }

                        } else if (enterNum == 2) {

                            int normalID = 0;
                            try {
                                normalID = normalUser.loginCheck(normalUL);
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                            while(true){
                                tool.page4();
                                System.out.print("请输入你需要操作功能的数字:");
                                int onetwo1 = scan.nextInt();   //  选择功能数字
                                if(onetwo1==1){                 //  1.查看所有图书
                                    try {
                                        book.viewAllBook(bookL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;
                                } else if (onetwo1==2) {        //  2.借阅图书
                                    try {
                                        book.borrowBook(bookL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;
                                } else if (onetwo1==3) {        //  3.归还图书
                                    try {
                                        book.giveBackBook(bookL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;
                                } else if (onetwo1==4) {        //  4.显示用户信息(只能查看自己的用户信息)
                                    try {
                                        normalUser.myInformation(normalID,normalUL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;
                                } else if (onetwo1==5) {        //  5.修改用户信息(只能修改自己的用户信息)
                                    System.out.print("\n请输入你要修改的信息的选项(1普通用户账号名2手机号码" +
                                            "3身份证号码4密码5姓名6性别7专业8住址信息):");
                                    int  num=scan.nextInt();   //  normalchange  修改序号
                                    try {
                                        normalUser.normalAlter( num, normalID,normalUL);
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;
                                } else if (onetwo1==6) {        //  6.退出系统
                                    System.out.print("\n谢谢使用,欢迎下次光临!");
                                    System.exit(0);;
                                }
                            }
                        }
                    case 2:
                        tool.page5();
                        System.out.print("请输入要选择要操作的序号(只能输入1,2):");
                        int registernum   = scan.nextInt();               //注册管理员或者普通用户
                        while(true){
                            if(registernum>0||registernum<3){
                                break;
                            }else {
                                System.out.println("输入序号错误,请重新输入要操作的序号(只能输入1,2):");
                                registernum   = scan.nextInt();
                            }
                        }
                        if(registernum==1){
                            try {
                                adminUser.addAdminUser(adminUL);
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                            continue;

                        } else if (registernum==2) {
                            try {
                                normalUser.addNormalUser(normalUL);
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                            continue;
                        }
                    case 3:
                        System.out.println("谢谢使用,欢迎下次光临!");
                        System.exit(0);;
                }

            }
        }
    }

}

初始化相关txt文件:

Admin.txt

root,1111,2222,123456,lisi,男,计算机,安徽

Normal.txt

normal,1234,5678,654321,梦洛,女,艺术,北京

Book.txt

C语言,50.0,58
Python,50.0,50

五、项目运行结果

        说明一下:这里并没有校验输入数据限制,是没写,太麻烦了,读者想要校验输入格式可以自行实现。

        说明:这里进行了完成的功能展示。

普通用户注册:

查看Normal.txt文件

​普通用户登录功能查看:

功能1:查看所有图书

功能2:借阅图书

验证图书数目是否减少响应数目:

功能3:归还图书

验证图书归还后数目是否正确:

功能4:显示用户信息

功能5:修改用户信息

查看用户信息是否修改成功:

功能6:退出系统:

管理员账户注册:

注册是否成功,查看Admin.txt

管理员用户功能查看:

1查看所有图书:

2添加图书

3修改图书

4删除图书

5查看所有普通用户信息

6查看管理员账号信息

7修改管理员账号信息

8退出登录

六、项目难点分析

1、校验功能数字是自己规定的数字

        使用while(true){}循环实现,在循环体中设置只有输入规定数字才能跳出循环,执行后面的代码。

      System.out.print("请输入要选择要操作的序号(只能输入1,2):");
      int enterNum =scan.nextInt();  //enterNum登录数字  1.管理员  2.用户
      while(true){
            if(enterNum == 1||enterNum == 2 ){
                break;
            }else{
                System.out.print("输入错误,请从从新输入要选择要操作的序号(只能输入1,2):");
                enterNum =scan.nextInt();
             }
      }
2、明确变量的定义域

要清楚自己定义的变量作用的范围:

        在Java中,变量的作用域决定了变量在程序中可见的范围。如果一个变量被定义在一个代码块内部,那么它的作用域就被限制在该代码块内部。如果一个变量被定义在方法内部,那么它的作用域就被限制在该方法内部。如果一个变量被定义在类内部但方法之外,那么它的作用域就是整个类。

        这里要注意的是,作用范围大的变量,例如adminUser、bookName...等等,要定义在整个循环体的外面,若是定义在while(){}、for(;;){}、do{}while()三种循环和if(){}else{}、switch(){}选择语句中变量,作用域只能在循环体或者选择语句中,只用在循环体或者选择语句中使用,此范围之外,不能使用,或者可能出现操作该变量失效的现象。

3、将其划分为不同的类,在不同类里面进行不同类单独的属性方法的开发与封装。
4、文件的读取和写入

        这里必须完成数据的读取才能创建写入操作,若FileRead和FileWriter:

FileRead fileRead = new FileRead(file);
FileWriter fileWriter = new FileWriter(File);

        以上述方式同时创建,这两个线程同时创建,FileWriter会打开一个空文件,会把原本文件中的数据全部清空,这样FileReader对象读取时会读取一个空文件,不会返回任何内容,造成Bug,所以必须在读取文件所有内容和对内容的操作完成之后创建FileWriter对象。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/424738.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

代码随想录算法训练营第四十天|139.单词拆分,多重背包介绍,背包问题总结篇!

系列文章目录 代码随想录算法训练营第一天|数组理论基础&#xff0c;704. 二分查找&#xff0c;27. 移除元素 代码随想录算法训练营第二天|977.有序数组的平方 &#xff0c;209.长度最小的子数组 &#xff0c;59.螺旋矩阵II 代码随想录算法训练营第三天|链表理论基础&#xff…

创建型模式之原型模式

一、概述 1、工作原理&#xff1a;将一个原型对象传给要发动创建的对象(即客户端对象),这个要发动创建的对象通过请求原型对象复制自己来实现创建过程 2、通过克隆方法所创建的对象是全新的对象&#xff0c;它们在内存中拥有新的地址&#xff0c;每一个克隆对象都是独立的 3…

虚拟线程目前不推荐上生产的个人思考

1. pin 线程引发的问题比预期严重&#xff0c;需要修改的库繁多 截止目前 Java 21 虚拟线程一些比较严重的 Bug&#xff1a; 1. Thread.HoldsLock(Object) 这个方法&#xff0c;如果是虚拟线程调用&#xff0c;会在平台线程获取到锁之后&#xff0c;就算切换虚拟线程&#xf…

JavaScript闭包漏洞与修补措施

请先看下面一段代码 var obj (function () {var sonObj {a: 1,b: 2}return {get: function (v) {return sonObj[v]}}})()可以看出,这是一段很典型的js闭包代码,可以通过obj调用get方法传一个参数,如果传的是a就可以得到闭包内的对象sonObj.a var obj (function () {var sonO…

2024真正有效的苹果mac电脑清理工具CleanMyMac X

一、前言 对于Mac用户来说&#xff0c;电脑卡顿、运行缓慢无疑是一件令人头疼的事情。而市面上的清理软件又五花八门&#xff0c;效果参差不齐&#xff0c;如何才能找到一款真正有效的清理工具呢&#xff1f;今天&#xff0c;我们为大家推荐一款实力派电脑清理软件——CleanMy…

Canvs的js库:Fabric.js简单强大,用于绘制各种图形

Fabric.js是一个用于创建交互式的HTML5 Canvas应用程序的JavaScript库。它提供了一个简单而强大的API&#xff0c;用于在Web浏览器中绘制和操作图形对象。Fabric.js可以用于创建各种图形应用程序&#xff0c;例如绘图编辑器、图像编辑器、流程图、地图和数据可视化等。 官网文…

图像物体的边界- 华为OD统一考试(C卷)

OD统一考试&#xff08;C卷&#xff09; 分值&#xff1a; 200分 题解&#xff1a; Java / Python / C 题目描述 给定一个二维数组M行N列&#xff0c;二维数组里的数字代表图片的像素&#xff0c;为了简化问题&#xff0c;仅包含像素1和5两种像素&#xff0c;每种像素代表一个…

C语言中的字符魔法:大小写转换的艺术

引言 在C语言的世界里&#xff0c;字符处理是一项基础且重要的任务。字符作为编程中最基本的元素之一&#xff0c;承担着信息展示、数据交互等多重角色。特别是在处理文本信息时&#xff0c;字符的转换和识别显得尤为重要。大小写字母的转换就是其中一个常见的需求&#xff0c…

STM32作为SPI slave与主机异步通信

背景 最近被测试提了个BUG&#xff0c;说某款产品在用户按下前面板的按键后&#xff0c;对应的按键灯没有亮起来。前面板跟主机是通过SPI口通信&#xff0c;前面板是从机&#xff0c;从机想要主动发送消息&#xff0c;需要通过GPIO中断来通知主机&#xff1a; 上图前面板是ST…

flurl升级之后没有FlurlNewtonsoftJsonSerializer

新建NewtonsoftJsonSerializer.cs /// <summary> /// ISerializer implementation based on Newtonsoft.Json. /// Default serializer used in calls to GetJsonAsync, PostJsonAsync, etc. /// </summary> public class NewtonsoftJsonSerializer : IJsonSerial…

【CSP试题回顾】202312-1-仓库规划

CSP-202312-1-仓库规划 解题思路 定义结构体和变量&#xff1a; 结构体 MyWareHouse&#xff0c;用来存储每个仓库的索引&#xff08;编号&#xff09;和位置编码。定义了整数 n 和 m&#xff0c;分别代表仓库的数量和位置编码的维数。定义了一个 vector<MyWareHouse> 的…

图解Vivado工程的目录结构

一、目录结构 ​在使用Vivado进行工程设计时&#xff0c;创建工程以及运行工程的过程中都会生成大量的目录和文件&#xff0c;下面图将对目录和文件结构及功能进行一个简单说明。 工程示例图 添加图片注释&#xff0c;不超过 140 字&#xff08;可选&#xff09; 二、参考资料…

ShardingJdbc分库分表-浅谈分表原理

文章目录 为什么要分库分表一、分库分表二、不停机分库分表数据迁移 为什么要分库分表 一般的机器&#xff08;4核16G&#xff09;&#xff0c;单库的MySQL并发&#xff08;QPSTPS&#xff09;超过了2k&#xff0c;系统基本就完蛋了。最好是并发量控制在1k左右。这里就引出一个…

kubesphere jenkins 流水线 未运行(解决方案)

场景&#xff1a; 在kubesphere 中运行 流水线 devops 结果&#xff0c;显示未运行 但是用 admin 账户是可以运行成功的。 问题解决 1- 查日志&#xff1a; 然后 Caused: org.acegisecurity.userdetails.UsernameNotFoundException: org.springframework.security.core.…

JVM运行时数据区——运行时数据区及线程概述

文章目录 1、运行时数据区概述2、线程3、小结 内存是非常重要的系统资源&#xff0c;是硬盘和CPU的中间仓库及桥梁&#xff0c;承载着操作系统和应用程序的实时运行。JVM在程序执行期间把它所管理的内存分为若干个不同的数据区域。这些不同的数据区域可以分为两种类型&#xff…

吴恩达机器学习全课程笔记第六篇

目录 前言 P96-P100 使用多个决策树 随机森林算法 XGBoost 什么时候使用决策树 P101-P107 聚类 K-means 初始化K-means 选择聚类的个数 P108-P113 异常检测算法 开发和评估异常检测系统 异常检测vs监督学习 选择要使用的特征 前言 这是吴恩达机器学习笔记的第…

【嵌入式实践】【芝麻】【设计篇-2】从0到1给电动车添加指纹锁:项目可行性分析

0. 前言 该项目是基于stm32F103和指纹模块做了一个通过指纹锁控制电动车的小工具。支持添加指纹、删除指纹&#xff0c;电动车进入P档等待时计时&#xff0c;计时超过5min则自动锁车&#xff0c;计时过程中按刹车可中断P档状态&#xff0c;同时中断锁车计时。改项目我称之为“芝…

基于反光柱特征的激光定位算法思路

目录 1. 识别反光柱2. 数据关联2.1 基于几何形状寻找匹配2.2 暴力寻找匹配 3. 位姿估计&#xff08;最小二乘求解&#xff09;4. 问题4.1 精度问题4.2 快速旋转时定位较差 1. 识别反光柱 反光柱是特殊材料制成&#xff0c;根据激光雷达对反光材料扫描得到的反射值来提取特征。…

如何解决微服务的数据一致性分发问题?

介绍 系统架构微服务化以后,根据微服务独立数据源的思想,每个微服务一般具有各自独立的数据源,但是不同微服务之间难免需要通过数据分发来共享一些数据,这个就是微服务的数据分发问题。Netflix/Airbnb等一线互联网公司的实践[参考附录1/2/3]表明,数据一致性分发能力,是构…

京东云硬钢阿里云:承诺再低10%

关注卢松松&#xff0c;会经常给你分享一些我的经验和观点。 阿里云刚刚宣布史上最大规模的全线产品降价20%&#xff0c;这热度还没过&#xff0c;京东云当晚就喊话&#xff1a;“随便降、比到底!&#xff0c;全网比价&#xff0c;击穿低价&#xff0c;再低10%”&#xff0c;并…