项目复习

Courier

public class Courier extends Person {
    private String courisrId;

    public  Courier(){
    }
    public  Courier(String courisrId ,String pwd){
        super.setPwd(pwd);
        this.courisrId = courisrId;
    }
    public Courier(String courisrId, String name, String sex ,int age , String pwd){
        super(name,age,pwd,sex);
        this.courisrId = courisrId;
    }
    public String getCourisrId(){
        return  courisrId;
    }
    public void setCourisrId(String courisrId){
        this.courisrId= courisrId;
    }
    @Override
    public  String toString(){
        return "Courier{" +
                "courierId='" + courisrId +'\'' +
                ", name='" + getName() +'\''+
                ", age='" +  getAge()  +'\''+
                ", pwd=" + getPwd() +'\'' +
                ", sex='" + getSex() +'\'' +
                '}';
    }
}

Person

public class Person {
    private String name;
    private int age;
    private String pwd;
    private String sex;


    public Person() {
    }

    public Person(String name, int age, String pwd, String sex ) {
        this.name = name;
        this.age = age;
        this.pwd = pwd;
        this.sex = sex;
        
    }

    


    public String getName() {
        return name;
    }

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

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }


}

LoginService

public class LoginService {
    private Scanner sc = null;

    public LoginService(Scanner scanner) {
        this.sc = scanner;
    }

    /**
     * 用户注册
     */
    public void register(Scanner sc) {
        System.out.println("请输入用户编码:");
        String clientId = sc.next();
        System.out.println("请输入用户的密码:");
        String pwd = sc.next();
        System.out.println("请输入用户名");
        String name = sc.next();
        System.out.println("请输入年龄:");
        int age = sc.nextInt();
        System.out.println("请输入性别:");
        String sex = sc.next();
        System.out.println("请输入手机号码:");
        String phone = sc.next();

        Customer customer = Customer.builder().setCustomerId(clientId).setCustomerId(pwd);
        customer.setName(name);
        customer.setAge(age);
        customer.setPhone(phone);
        customer.setSex(sex);
        // 把上面的对象保存到数组
        // CustomerData.save(customer);

    }
}

CourierData

public class CourierData {
    private  static  int SIZE = 10;  //一共能储存的用户数
    private  static  int COUNT = 0;  // 已经存储的用户
    private  static Customer[] CUSTOMERDATA = new  Customer[SIZE];

    public static void save(Customer customer){
        if (COUNT== SIZE){
            CUSTOMERDATA = Arrays.copyOf( CUSTOMERDATA , SIZE*2);
            SIZE*=2;
        }
        for (int i = 0; i< CUSTOMERDATA.length; i++){
            if (null == CUSTOMERDATA[i]){
                CUSTOMERDATA[i] =customer;
                COUNT++;
                return;
            }
        }
    }
     // 从数组中查询用户的信息
    public  static  Customer get(String customerId , String pwd){
        for (Customer c  : CUSTOMERDATA){
            if(c.getCustomerId().equals(customerId) && c.getPwd().equals(pwd)){
                return  c;
            }
        }
        return  null;
    }
    // 只根据id查询用户
    public static Customer get(String customerId){
        for (Customer c : CUSTOMERDATA){
            if (customerId.equals(c.getCustomerId())){
                return  c;
            }
        }
        return  null;
    }
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 文件的目录结构 main.js中创建一个vue实例,引用了APP组件 APP组件中,使用router-view去配...
    Gopal阅读 357评论 0 1
  • 三、客户端 定时器的功能可以实时更新用户列表—— 需要加上while(1),因为如果数据包是这样的—— 3.1 弹...
    StevenHD阅读 523评论 0 0
  • 关于移动端适配 移动端适配方案(上)移动端适配方案(下)参考 rem布局 关于移动端rem布局的总结
    Gopal阅读 234评论 0 2
  • 一、客户端登录 首先,信号与槽机制——login(),然后就是connected() 然后,相当于现在已经登录成功...
    StevenHD阅读 426评论 0 0
  • 概念 一个PushButton按钮显示在Widget窗口上,就是父子窗口 一、内存管理 一定要在堆上建立对象,在栈...
    StevenHD阅读 348评论 0 0