首页 > 其他分享 >BikeManage共享单车管理系统

BikeManage共享单车管理系统

时间:2022-11-26 11:13:54浏览次数:42  
标签:管理系统 BikeManage System bikeCompanies println import 单车 out

bean:

package com.javasm.bean;

import com.javasm.util.Utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-11:23
 * @Since:jdk1.8
 * @Description:
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Bike {
    //单车编号
    private Integer bikeId;
    //单车名称
    private String bikeName;
    //单车状态(0.未借出  1.已借出)
    private Integer bikeState;
    //借出时间
    private Date lendTime;
    //借出用户
    private User lendUser;

    @Override
    public String toString() {
        return "Bike{" +
                "bikeId=" + bikeId +
                ", bikeName='" + bikeName + '\'' +
                ", bikeState=" + (bikeState !=null&&bikeState==0 ?"未借出" : "已借出" )+
                ", lendTime='" + (lendTime ==null?"未借出" :Utils.format(lendTime)) + '\'' +
                ", lendUser=" + (lendUser==null ? "未借出" : lendUser.getName()) +
                '}';
    }
}
package com.javasm.bean;

import cn.hutool.core.codec.Base64;
import lombok.*;


import java.util.Date;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-11:13
 * @Since:jdk1.8
 * @Description:
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User {
    //账号
    private int id;
    //密码
    private String pwd;
    //真实姓名
    private String name;
    //账户余额
    private float balance;
    //角色(0.用户 1.管理员)
    private int userRole;
    //注册时间
    private Date regTime;
    //最后登录时间
    private Date lastLoginTime;
    //自增id
    private static  int identityId=1000;

    /**
     * 全参构造
     * @param pwd
     * @param name
     * @param balance
     * @param userRole
     * @param regTime
     * @param lastLoginTime
     */
    public User(String pwd, String name, float balance, int userRole, Date regTime, Date lastLoginTime) {
        this.id = identityId++;
        //密码加密
        this.pwd = Base64.encode(pwd);
        this.name = name;
        this.balance = balance;
        this.userRole = userRole;
        this.regTime = regTime;
        this.lastLoginTime = lastLoginTime;
    }

}
package com.javasm.bean;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Arrays;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-11:23
 * @Since:jdk1.8
 * @Description:
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class BikeCompany {
    //公司编号
    private Integer companyId;
    //公司名称
    private String companyName;
    //单车列表
    private Bike[] bikes;
    //单车总数
    private Integer sum;
    //出借次数
    private Integer lendCount;

    @Override
    public String toString() {
        return "BikeCompany{" +
                "companyId=" + companyId +
                ", companyName='" + companyName + '\'' +
//                ", bikes=" + Arrays.toString(bikes) +
                ", sum=" + sum +
                ", lendCount=" + lendCount +
                '}';
    }
}

constants:

package com.javasm.constants;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-17:15
 * @Since:jdk1.8
 * @Description:
 */
public class BikeConstants {
    //公司名称
    public static final String OFO ="ofo";
    public static final String MO_BAI ="摩拜";
    public static final String HALO ="哈啰";

    //单车借出状态(0.未借出 1.已借出)
    public static final int LEND_STATE =1;
    public static final int UN_LEND_STATE =0;
}
package com.javasm.constants;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-15:35
 * @Since:jdk1.8
 * @Description:
 */
public class UserConstants {
    //用户角色(0.普通用户 1.系统管理员)
    public static final int ADMIN_ROLE =1;
    public static final int USER_ROLE =0;

}

action:

package com.javasm.action;

import cn.hutool.core.date.DateUtil;
import com.javasm.bean.User;
import com.javasm.constants.UserConstants;
import com.javasm.service.UserService;
import com.javasm.service.impl.UserServiceImpl;

import java.util.Scanner;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-15:05
 * @Since:jdk1.8
 * @Description:
 */
public class UserAction {
    static Scanner scanner =new Scanner(System.in);
    //初始化一组用户
    static User[] users =new User[3];
    //业务对象
    static UserService userService =new UserServiceImpl();

    static {
        System.out.println("数据正咋初始化·");
        users[0]=new User("123","tom",100,1,null,null);
        users[1]=new User("123","cat",100,1,null,null);
        users[2]=new User("123","jack",100,0,null,null);
    }

    public static void startMenu(){
        boolean b=true;
        while (b){
            System.out.println("******欢迎使用迷你共享单车系统******");
            System.out.println("\t\t1.登录");
            System.out.println("\t\t2.注册");
            System.out.println("\t\t0.退出");
            System.out.println("请选择:");
            int choose =scanner.nextInt();

            switch (choose){
                case 1:
                    login();
                    break;
                case 2:
                    users=userService.reg(users,scanner);
                    break;
                case 0:
                    System.out.println("谢谢使用,系统已退出");
                    b =false;
                    break;
            }


        }

    }

    /**
     * 用户登录
     */
    private static void login(){
        //用户登录
        User loginUser =userService.login(users,scanner);
        if(loginUser ==null){
            System.out.println("登录失败,账号或密码错误!");
            return;
        }
        //修改当前登录用户的登录时间(当前的系统时间)
        loginUser.setLastLoginTime(DateUtil.date());
        //根据登录用户判断角色,根据角色的不同进入到不同的菜单列表!
        if(loginUser.getUserRole()== UserConstants.ADMIN_ROLE){
            //进入到管理员菜单列表
            BikeAction.adminMenu(loginUser);
        }else {
            //进入到用户菜单列表
            BikeAction.userMenu(loginUser);
        }

    }

}
package com.javasm.action;

import com.javasm.bean.Bike;
import com.javasm.bean.BikeCompany;
import com.javasm.bean.User;
import com.javasm.constants.BikeConstants;
import com.javasm.service.BikeService;
import com.javasm.service.UserService;
import com.javasm.service.impl.BikeServiceImpl;
import com.javasm.service.impl.UserServiceImpl;
import com.javasm.util.Utils;

import java.util.Scanner;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-15:52
 * @Since:jdk1.8
 * @Description:
 */
public class BikeAction {
    static Scanner scanner = new Scanner(System.in);
    //单车列表
    static BikeCompany[] bikeCompanies = new BikeCompany[3];
    //业务对象
    static BikeService bikeService = new BikeServiceImpl();

    static {
        //第一家公司
        BikeCompany ofo = new BikeCompany(1, BikeConstants.OFO, null, 5, 1000);
        //这家公司下单车列表
        Bike[] ofoBikes = new Bike[ofo.getSum()];//公司单车数
        for (int i = 0; i < ofoBikes.length; i++) {
            int id = 100 + i;
            ofoBikes[i] = new Bike(id, BikeConstants.OFO + id, BikeConstants.UN_LEND_STATE,
                    null, null);
        }
        //将单车列表存入到公司中
        ofo.setBikes(ofoBikes);

        //第二家公司
        BikeCompany moBai = new BikeCompany(2, BikeConstants.MO_BAI, null, 10, 1770);
        //这家公司下单车列表
        Bike[] moBaiBikes = new Bike[moBai.getSum()];//公司单车数
        for (int i = 0; i < moBaiBikes.length; i++) {
            int id = 200 + i;
            moBaiBikes[i] = new Bike(id, BikeConstants.MO_BAI + id, BikeConstants.UN_LEND_STATE,
                    null, null);
        }
        //将单车列表存入到公司中
        moBai.setBikes(moBaiBikes);

        //第三家公司
        BikeCompany haLo = new BikeCompany(3, BikeConstants.HALO, null, 3, 500);
        //这家公司下单车列表
        Bike[] haLoBikes = new Bike[haLo.getSum()];//公司单车数
        for (int i = 0; i < haLoBikes.length; i++) {
            int id = 300 + i;
            haLoBikes[i] = new Bike(id, BikeConstants.HALO + id, BikeConstants.LEND_STATE,
                    Utils.parseDate("2022-10-10 16:02:03"), UserAction.users[2]);
        }
        //将单车列表存入到公司中
        haLo.setBikes(haLoBikes);

        //将三家公司存入到公司数组
        bikeCompanies[0] = ofo;
        bikeCompanies[1] = moBai;
        bikeCompanies[2] = haLo;
    }

    /**
     * 管理员菜单列表
     *
     * @param loginUser
     */
    static void adminMenu(User loginUser) {
        boolean b = true;
        while (b) {
            System.out.println("迷你共享单车管理系统>>>管理员菜单列表");
            System.out.println("欢迎您:" + loginUser.getName() + "\t\t角色:" +
                    Utils.getUserRoleName(loginUser.getUserRole()) +
                    "\t\t最后登录时间:" + loginUser.getLastLoginTime());
            System.out.println("\t\t1.查看单车");
            System.out.println("\t\t2.投放单车");
            System.out.println("\t\t3.删除单车");
            System.out.println("\t\t4.单车排行榜");
            System.out.println("\t\t5.查看全部注册用户");
            System.out.println("\t\t0.退出登录");
            System.out.println("请选择:");
            int choose = scanner.nextInt();
            switch (choose) {
                case 1:
                    bikeService.showBike(bikeCompanies);
                    break;
                case 2:
                    bikeService.dropBike(bikeCompanies, scanner);
                    break;
                case 3:
                    bikeService.deleteBike(bikeCompanies, scanner);
                    break;
                case 4:
                    bikeService.leaderboard(bikeCompanies);
                    break;
                case 5:
                    bikeService.showUser(UserAction.users);
                    break;
                case 0:
                    b = false;
                    break;
            }
        }
    }


    static void userMenu(User loginUser) {
        boolean b = true;
        while (b) {
            System.out.println("迷你共享单车管理系统>>>用户菜单列表");
            System.out.println("欢迎您:" + loginUser.getName() + "\t\t角色:" +
                    Utils.getUserRoleName(loginUser.getUserRole()) +
                    "\t\t最后登录时间:" + loginUser.getLastLoginTime());
            System.out.println("\t\t1.借出单车");
            System.out.println("\t\t2.归还单车");
            System.out.println("\t\t3.修改登录密码");
            System.out.println("\t\t4.余额充值");
            System.out.println("\t\t0.退出登录");
            System.out.println("请选择:");
            int choose = scanner.nextInt();
            switch (choose) {
                case 1:
                   bikeService.BorrowBike(bikeCompanies,loginUser, scanner);
                    break;
                case 2:
                    bikeService.RepaidBike(bikeCompanies,loginUser, scanner);
                    break;
                case 3:
                    bikeService.ChangePwd(loginUser,scanner);
                    break;
                case 4:
                    bikeService.Recharge(loginUser,scanner);
                    break;
                case 0:
                    b = false;
                    break;
            }

        }

    }
}

services:

package com.javasm.service;

import com.javasm.bean.User;

import java.util.Scanner;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-15:14
 * @Since:jdk1.8
 * @Description:
 */
public interface UserService {
    /**
     * 用户登录
     * @param users
     * @param scanner
     * @return
     */
    User login(User[] users, Scanner scanner);

    /**
     * 用户注册
     * @param users
     * @param scanner
     * @return
     */
    User[] reg(User[] users, Scanner scanner);


}
package com.javasm.service;

import com.javasm.bean.Bike;
import com.javasm.bean.BikeCompany;
import com.javasm.bean.User;

import java.util.Scanner;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-17:12
 * @Since:jdk1.8
 * @Description:
 */
public interface BikeService {

    /**
     * 查看单车
     *
     * @param bikeCompanies
     */
    void showBike(BikeCompany[] bikeCompanies);

    /**
     * 投放单车
     *公司的地址没变,不用返回BikeCompany[]
     * @param bikeCompany
     * @param scanner
     * @return
     */
    void dropBike(BikeCompany[] bikeCompany, Scanner scanner);

    /**
     * 删除单车
     *公司的地址没变,不用返回BikeCompany[]
     * @param bikeCompanies
     * @param scanner
     * @return
     */
    void deleteBike(BikeCompany[] bikeCompanies, Scanner scanner);

    /**
     * 单车排行榜
     *
     * @param bikeCompanies
     */
    void leaderboard(BikeCompany[] bikeCompanies);

    /**
     * 查看所有注册用户
     * @param users
     */
    void showUser(User[] users);


    /**
     * 普通用户-->借出单车
     *公司的地址没变,不用返回BikeCompany[]
     * @param bikeCompanies
     * @param scanner
     * @return
     */
    void BorrowBike(BikeCompany[] bikeCompanies,User user,Scanner scanner);

    /**
     * 普通用户-->归还单车
     * 公司的地址没变,不用返回BikeCompany[]
     * @param bikeCompanies
     * @param scanner
     * @return
     */
    void RepaidBike(BikeCompany[] bikeCompanies,User user,Scanner scanner);

    /**
     * 修改登入密码
     * @param user
     * @param scanner
     * @return
     */
    void ChangePwd(User user,Scanner scanner);

    /**
     * 余额充值
     * @param user
     * @param scanner
     */
    void  Recharge(User user,Scanner scanner);

}

serviceImpl:

package com.javasm.service.impl;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUtil;
import com.javasm.action.UserAction;
import com.javasm.bean.User;
import com.javasm.service.UserService;
import com.javasm.util.Utils;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-15:15
 * @Since:jdk1.8
 * @Description:
 */
public class UserServiceImpl implements UserService {
    @Override
    public User login(User[] users, Scanner scanner) {
        System.out.println("迷你共享单车管理系统>>>用户登录");
        System.out.println("请输入登录账号和密码:");
        int inputId =scanner.nextInt();
        //输入的密码直接加密!
        String inputPwd=Base64.encode(scanner.next());

        //根据账号和密码查找登录的用户
        return getUserByIdAndPwd(inputId,inputPwd,users);

    }

    @Override
    public User[] reg(User[] users, Scanner scanner) {
        System.out.println("迷你共享单车管理系统>>>用户注册");
        System.out.println("请输入密码:");
        String inputPwd =scanner.next();
        System.out.println("请输入真实姓名:");
        String inputName =scanner.next();
     users=Arrays.copyOf(users,users.length+1);
     users[users.length-1]=new User(inputPwd,inputName,100,0,DateUtil.date(),null);
        System.out.println("注册成功");
        System.out.println("你的id为:"+ users[users.length-1].getId());
        return users;
    }

    /**
     * 根据登录的账号和密码查找用户信息
     * @param id
     * @param pwd
     * @param users
     * @return
     */
    private User getUserByIdAndPwd(int id,String pwd,User[] users){
        for (User user : users) {
            //验证账号 密码:加密之后的密码
            if(id==user.getId()&&pwd.equals(user.getPwd())){
                return user;
            }
        }
        return null;
    }
}
package com.javasm.service.impl;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.javasm.bean.Bike;
import com.javasm.bean.BikeCompany;
import com.javasm.bean.User;
import com.javasm.constants.BikeConstants;
import com.javasm.service.BikeService;
import jdk.nashorn.internal.ir.ReturnNode;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-17:12
 * @Since:jdk1.8
 * @Description:
 */
public class BikeServiceImpl implements BikeService {
    /**
     * 查看单车
     *
     * @param bikeCompanies
     */
    @Override
    public void showBike(BikeCompany[] bikeCompanies) {
        System.out.println("迷你共享单车管理系统>>>管理员操作>>>查看单车");
        for (BikeCompany bikeCompany : bikeCompanies) {
            System.out.println(bikeCompany);
            //该公司下单车信息
            Bike[] bikes = bikeCompany.getBikes();
            for (Bike bike : bikes) {
                System.out.println(bike);
            }
            System.out.println("----------------------");
        }
    }

    /**
     * 投放单车
     *
     * @param bikeCompanies
     * @param scanner
     * @return
     */
    @Override
    public void dropBike(BikeCompany[] bikeCompanies, Scanner scanner) {
        System.out.println("迷你共享单车管理系统>>>管理员操作>>>投放单车");
        //展示单车公司
        showCompanies(bikeCompanies);
        System.out.println("请选择要投放的单车品牌:");
        int inputId = scanner.nextInt();
        //得到输入单车公司index;
        int index = getBikeCompanyById(bikeCompanies, inputId);
        if (index == -1) {
            return ;
        }
        System.out.println("请输入投放的单车数量:");
        int inputNum = scanner.nextInt();
        System.out.println("空间不足,已参照配置进行扩容!");
        System.out.println("投放" + inputNum + "辆" + bikeCompanies[index].getCompanyName() + "车成功!");
        //该公司的单车列表
        Bike[] bikes = bikeCompanies[index].getBikes();
        //扩容
        Bike[] bikes1 = Arrays.copyOf(bikes, bikes.length + inputNum);

        for (int i = bikes.length; i < bikes1.length; i++) {
            int id = bikes[bikes.length - 1].getBikeId() + i - bikes.length + 1;
            bikes1[i] = new Bike(id, bikeCompanies[index].getCompanyName() + id, BikeConstants.UN_LEND_STATE,
                    null, null);
        }
        //将扩容之后的数组反填充
        bikeCompanies[index].setBikes(bikes1);
        bikeCompanies[index].setSum(bikeCompanies[index].getSum() + inputNum);
    }

    /**
     * 删除单车
     *
     * @param bikeCompanies
     * @param scanner
     * @return
     */
    @Override
    public void deleteBike(BikeCompany[] bikeCompanies, Scanner scanner) {
        System.out.println("迷你共享单车管理系统>>>管理员操作>>>删除单车");
        showCompanies(bikeCompanies);
        System.out.println("请选择要操作的单车品牌:");
        int inputId = scanner.nextInt();
        int index = getBikeCompanyById(bikeCompanies, inputId);
        if (index == -1) {
            return ;
        }
        //循环输出该单车
        Bike[] bikes = bikeCompanies[index].getBikes();
        for (Bike bike : bikes) {
            System.out.println(bike);
        }
        //如果该公司只有一辆车了,则无法删除单车
        if(bikeCompanies[index].getSum()==1){
            System.out.println("单车公司至少有一辆车,删不了了!!!");
            return;
        }
        System.out.println("请录入要删除的单车编号:");
        int inputBikeId = scanner.nextInt();
        //得到操作单车的索引
        int bikeIndex = getBikeByID(bikeCompanies, index, inputBikeId);
        if (bikeIndex == -1) {
            return;
        }

        //单车存在则判断单车借出状态
        if(bikes[bikeIndex].getBikeState()==1){
            System.out.println("该单车已借出,无法操作");
            return;
        }
        System.out.println("删除" + bikeCompanies[index].getCompanyName() +
                "公司下的" + bikes[bikeIndex].getBikeName() + "车成功!");
        //循环覆盖
        for (int i = bikeIndex; i < bikes.length - 1; i++) {
            bikes[i] = bikes[i + 1];
        }
        bikes = Arrays.copyOf(bikes, bikes.length - 1);
        bikeCompanies[index].setBikes(bikes);
        bikeCompanies[index].setSum(bikeCompanies[index].getSum() - 1);
    }

    /**
     * 单车排行榜
     *
     * @param bikeCompanies
     */
    @Override
    public void leaderboard(BikeCompany[] bikeCompanies) {
        System.out.println("迷你共享单车管理系统>>>管理员操作>>>单车排行榜");
        System.out.println("单车公司名称-->借出次数");
        for (int i = 0; i < bikeCompanies.length - 1; i++) {
            for (int j = 0; j < bikeCompanies.length - 1 - i; j++) {
                if (bikeCompanies[j].getLendCount() < bikeCompanies[j + 1].getLendCount()) {
                    BikeCompany temp = bikeCompanies[j + 1];
                    bikeCompanies[j + 1] = bikeCompanies[j];
                    bikeCompanies[j] = temp;
                }
            }
        }
        for (BikeCompany bikeCompany : bikeCompanies) {
            System.out.println(bikeCompany.getCompanyName() + "-->" + bikeCompany.getLendCount());
        }

    }

    /**
     * 查看所有注册用户
     *
     * @param users
     */
    @Override
    public void showUser(User[] users) {
        System.out.println("迷你共享单车管理系统>>>管理员操作>>>查看所有注册用户");
        for (User user : users) {
            System.out.println(user);
        }
    }

    /**
     * 借出单车
     *
     * @param bikeCompanies
     * @param scanner
     * @return
     */
    @Override
    public void BorrowBike(BikeCompany[] bikeCompanies,User user, Scanner scanner) {
        System.out.println("迷你共享单车管理系统>>>借出单车");
        showCompanies(bikeCompanies);
        System.out.println("请选择要操作的单车品牌:");
        int inputId = scanner.nextInt();
        int index = getBikeCompanyById(bikeCompanies, inputId);
        if (index == -1) {
            return ;
        }
        System.out.println("此<" + bikeCompanies[index].getCompanyName() + ">单车有共享单车如下:");
        //循环输出该单车公司下的单车
        Bike[] bikes = bikeCompanies[index].getBikes();
        for (Bike bike : bikes) {
            System.out.println(bike);
        }
        System.out.println("请输入你要借出的单车编号:");
        int inputBikeID=scanner.nextInt();
        int bikeIndex=getBikeByID(bikeCompanies,index,inputBikeID);
        if (bikeIndex == -1) {
            return ;
        }
        if(bikes[bikeIndex].getBikeState()==1){
            System.out.println("该单车已借出,无法借出");
            return ;
        }
        //单车借出状态,借出时间,借出人,公司借出次数都改变
        bikes[bikeIndex].setBikeState(BikeConstants.LEND_STATE);
        bikes[bikeIndex].setLendTime(DateUtil.date());
        bikes[bikeIndex].setLendUser(user);
        bikeCompanies[index].setLendCount(bikeCompanies[index].getLendCount()+1);

        System.out.println("借出<"+ bikeCompanies[index].getCompanyName() +">公司下的<"+ bikes[bikeIndex].getBikeName() +">车成功!");

    }

    /**
     * 归还单车
     * @param bikeCompanies
     * @param scanner
     * @return
     */
    @Override
    public void RepaidBike(BikeCompany[] bikeCompanies,User user, Scanner scanner) {
        System.out.println("迷你共享单车管理系统>>>归还单车");
        showCompanies(bikeCompanies);
        System.out.println("请选择要操作的单车品牌:");
        int inputId =scanner.nextInt();
        int index = getBikeCompanyById(bikeCompanies,inputId);
        if (index == -1) {
            return ;
        }
        System.out.println("此<"+ bikeCompanies[index].getCompanyName() +">单车有共享单车如下:");
        Bike[] bikes = bikeCompanies[index].getBikes();
        for (Bike bike : bikes) {
            System.out.println(bike);
        }
        System.out.println("请输入你要归还的单车编号:");
        int inputBikeID=scanner.nextInt();
        int bikeIndex=getBikeByID(bikeCompanies,index,inputBikeID);
        if (bikeIndex == -1) {
            return ;
        }
        if(bikes[bikeIndex].getBikeState()==0){
            System.out.println("该单车未借出,无法归还");
            return ;
        }
        if(!user.equals(bikes[bikeIndex].getLendUser())){
            System.out.println("你不是该单车借出人,无法归还该单车!");
            return ;
        }
        //计算用时以及需支付的金额!
        long time=DateUtil.between(bikes[bikeIndex].getLendTime(),DateUtil.date(),DateUnit.SECOND);
        float money =time * 1;
        if(money>user.getBalance()){
            System.out.println("余额不足,请充值");
            return ;
        }else{
            user.setBalance(user.getBalance()-money);
        }
        System.out.println("用车<"+time+">秒,需支付<"+money+">元");
        //单车借出状态,借出时间,借出人改变
        bikes[bikeIndex].setBikeState(BikeConstants.UN_LEND_STATE);
        bikes[bikeIndex].setLendTime(null);
        bikes[bikeIndex].setLendUser(null);
        System.out.println("归还<"+ bikeCompanies[index].getCompanyName() +">公司下的<"+bikes[bikeIndex].getBikeName() +">车成功!");

    }

    /**
     * 修改密码
     * @param user
     * @param scanner
     */
    @Override
    public void ChangePwd(User user, Scanner scanner) {
        System.out.println("迷你共享单车管理系统>>>修改登入密码");
        System.out.println("请输入原密码:");
        String oldPwd = Base64.encode(scanner.next());
        if(!user.getPwd().equals(oldPwd)){
            System.out.println("原密码输入错误!");
            return ;
        }
        System.out.println("请输入新密码:");
        String newPwd = Base64.encode(scanner.next());
            if(user.getPwd().equals(newPwd)){
                System.out.println("新密码与原密码不能一致");
                return ;
            }
            user.setPwd(newPwd);
        System.out.println("修改成功");
    }

    /**
     * 余额充值
     * @param user
     * @param scanner
     */
    @Override
    public void Recharge(User user, Scanner scanner) {
        System.out.println("迷你共享单车管理系统>>>余额充值");
        System.out.println("请输入充值金额:");
        float inputMoney =scanner.nextFloat();
        if(inputMoney<10||inputMoney>1000){
            System.out.println("充值失败!");
        }
        user.setBalance(user.getBalance()+inputMoney);
        System.out.println("充值成功!余额为:"+user.getBalance());

    }

    /**
     * 展示所有单车公司
     *
     * @param bikeCompanies
     */
    private static void showCompanies(BikeCompany[] bikeCompanies) {
        for (int i = 0; i < bikeCompanies.length; i++) {
            System.out.println(bikeCompanies[i].getCompanyId() + "-->" + bikeCompanies[i].getCompanyName());
        }
    }

    /**
     * 得到要操作单车公司索引
     *
     * @param bikeCompanies
     * @param inputId
     * @return
     */
    private static int getBikeCompanyById(BikeCompany[] bikeCompanies, int inputId) {
        int index = -1;
        for (int i = 0; i < bikeCompanies.length; i++) {
            if (bikeCompanies[i].getCompanyId() == inputId) {
                index = i;
            }
        }
        if (index == -1) {
            System.out.println("该公司不存在");
            return index;
        }
        return index;
    }

    /**
     * 得到操作单车的索引
     *
     * @param bikeCompanies
     * @param index
     * @param inputBikeId
     * @return
     */
    private static int getBikeByID(BikeCompany[] bikeCompanies, int index, int inputBikeId) {
        Bike[] bikes = bikeCompanies[index].getBikes();
        int bikeIndex = -1;
        for (int i = 0; i < bikes.length; i++) {
            if (bikes[i].getBikeId() == inputBikeId) {
                bikeIndex = i;
            }
        }
        if (bikeIndex == -1) {
            System.out.println("该单车不存在");
            return bikeIndex;
        }

        return bikeIndex;
    }

}

util:

package com.javasm.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-15:57
 * @Since:jdk1.8
 * @Description:
 */
public class Utils {

    /**
     * 根据角色编号获取对应的文本
     * @param roleId
     * @return
     */
    public static String getUserRoleName(int roleId){
        return roleId == 0 ? "普通用户" : "系统管理员";
    }

    /**
     * 日期格式化:将字符串转成date日期类型
     * @param time
     * @return
     */
    public static Date parseDate(String time) {
        /*
             日期格式:
             yyyy 或者 yy : 2022    22
             MM:月份
             dd:日期

             HH:24小时制  hh:12小时制
             mm:分
             ss:秒

             E:星期几
         */
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 日期格式化:将date转成字符串
     * @param date
     * @return
     */
    public static String format(Date date){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
}

test:

package com.javasm.test;

import com.javasm.action.UserAction;

/**
 * @Author:Zxb
 * @Version:1.0
 * @Date:2022/11/24-17:53
 * @Since:jdk1.8
 * @Description:
 */
public class Start {
    public static void main(String[] args) {
        UserAction.startMenu();
    }
}

 

标签:管理系统,BikeManage,System,bikeCompanies,println,import,单车,out
From: https://www.cnblogs.com/19981206-zxb/p/16927072.html

相关文章