Feige快递系统

com.feige
Main:

package com.feige;

import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);
    public Main(){
    }
    public void menu() {
        System.out.println("============");
        System.out.println("\t\t欢迎使用快递系统\t\t");
        System.out.println("============");
        System.out.println("1 用户注册");
        System.out.println("2 用户注册");
        System.out.println("3 商品查看");
        System.out.println("4 商品查看");
        System.out.println("请输入:");
        int funNo = sc.nextInt();
        switch (funNo) {
            case 1:
                //用户注册
                break;
            case 2:
                //登陆系统
                break;
            case 3:
                //商品查看
                break;
            case 4:
                //退出系统
            default:
                sc.close();//关闭扫描器资源
                System.exit(0);// 0 正常退出  非0 非正常的中断退出
        }
    }

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

com.feige.beans
Person:

package com.feige.beans;

import java.security.PublicKey;

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;
    }
}

Customer:

package com.feige.beans;

public class Customer extends Person{
    private String customerId;
    private String phone;

    public Customer(){
    }


    //构建器 用来构建一个对象
    public static Customer builder(){
        return new Customer();
    }

    public String getCustomerId() {
        return customerId;
    }

    public Customer setCustomerId(String customerId) {
        this.customerId = customerId;
        return this;
    }

   public Customer Pwd(String pwd) {
        super.setPwd(pwd);
        //this.pwd = pwd ;
       return this;
   }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}

Courier:

package com.feige.beans;

public class Courier extends Person{
    private String courierId;

    public Courier(){
    }
    public Courier(String courierId, String pwd){
        super.setPwd(pwd);
        this.courierId = courierId;
    }
    public Courier(String courierId, String name, String sex, int age , String pwd) {
        super(name,age,pwd,sex);//super只能出现在方法的第一行
        this.courierId = courierId;
    }

    public String getCourierId() {
        return courierId;
    }

    public void setCourierId(String courierId) {
        this.courierId = courierId;
    }

    @Override
    public String toString() {
        return "Courier{" +
                "CourierId'" + courierId +'\''+
                ",name='" +getName() +'\'' +
                ",age='" +getAge() +'\'' +
                ",pwd='" +getPwd() +'\'' +
                ",sex='" +getSex() +'\'' +
                '}';
    }
}

com.feige.service
LoginService :

package com.feige.service;

import com.feige.beans.Customer;

import java.util.Scanner;

public class LoginService {
    private Scanner sc = null;

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

    //注册
    public void register() {
        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).Pwd(pwd);
       customer.setName(name);
       customer.setAge(age);
       customer.Pwd(pwd);
       customer.setSex(sex);
       // 把上面的对象保存到数组
       // CustomerData.save(customer);
    }
}

com.feige.tools
CustomerData:

package com.feige.tools;

import com.feige.beans.Customer;

import java.util.Arrays;
import java.util.PropertyResourceBundle;

public class CustomerData {
    private static int SIZE = 10;  // 一共能存储的用户数
    private static int COUNT = 0;  // 已经存储的用户
    private static Customer[] CUSTOMERDATA = new Customer[SIZE];
    //把新增的用户保存在数组中
    public static void sava(Customer customer ) {
        if (COUNT == SIZE ) {  // 数组满了,扩容为原来的2倍
            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;
    }

}

//P:目前只有这么多 ,剩下的有空再更新

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

推荐阅读更多精彩内容

  • 重点 MVC:Model模型 View 视图 Controller 控制器数据的流转过程正向的过程:view==...
    法宝_阅读 273评论 0 0
  • package com.feige.tools; import com.feige.beans.Customer;...
    法宝_阅读 268评论 0 1
  • package com.feige.beans; public class Customer extends Pe...
    法宝_阅读 156评论 0 0
  • MySQL逻辑架构 下面是一幅MySQL各组件之间如何协同工作的架构图,有助于我们深入理解MySQL服务器。 如图...
    骑小猪看流星阅读 4,842评论 2 135
  • 前端开发面试题 面试题目: 根据你的等级和职位的变化,入门级到专家级,广度和深度都会有所增加。 题目类型: 理论知...
    怡宝丶阅读 2,625评论 0 7