Java拼电商客户管理系统

模拟通过文本对电商客户进行管理,熟悉面向对象编程,主要涉及以下知识点:

类的结构使用:属性,方法,构造器
对象的创建和使用
类的封装性声明和数组使用
数组插入删除及修改

实现的目标如下:
初始界面,
总共通过三个类来完成,Customer(客户类),CustomerList(客户管理类),CustomerView(界面管理类)

客户类的实现

/**
 * @Author:cgn
 * @Description 客户类:设定属性  姓名,性别,年龄,电话,邮箱
 *                      添加无参及有参构造器
 * @date
 */
public class Customer {
    private String name;
    private char sex;
    private int age;
    private String tel;
    private String email;

    public Customer() {
    }

    public Customer(String name, char sex, int age, String tel, String email) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.tel = tel;
        this.email = email;
    }


    public String getName() {
        return name;
    }

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

    public char getSex() {
        return sex;
    }

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

    public int getAge() {
        return age;
    }

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

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }


}

客户管理类的实现:

/**
 * @Author:cgn
 * @Description Customr管理类
 * @date
 */
public class CustomerList {
    private Customer[] customers;
    private int total = 0;

    /**
     *创建对象时,同时定义数组
     * @param totalCustomer
     */
    public CustomerList(int totalCustomer){
        customers = new Customer[totalCustomer];
    }

    public int getTotal(){
        return total;
    }

    //添加客户
    public boolean addCustomer(Customer customer){
        boolean flag = false;
        if(this.getTotal() >= customers.length){
            return false;
        }else{
            customers[total] = customer;
            this.total++;
            System.out.println("添加成功");
            return true;
        }
    }

    //修改客户信息
    public boolean replaceCustomer(int index,Customer cust){
        if(index < 0 || index >= this.getTotal()){
            System.out.println("输入的用户不存在");
            return false;
        }else{
            customers[index] = cust;
            System.out.println("修改客户信息成功");
            return true;
        }
    }

    //删除客户信息
    public boolean deleteCustomer(int index){
        boolean flag = false;
        if(index < 0 || index >= this.getTotal()){
            System.out.println("输入的用户不存在");
            flag =  false;
        }else{
            for(int i = index;index < this.getTotal();index++){
                customers[index] =customers[index +1];
                this.total--;
                System.out.println("删除成功");
                flag =  true;
            }
        }
        return flag;
    }

    //查询客户列表
    public Customer[] getCustomers(){
        return customers;
    }

    //查询索引是index的客户信息
    public Customer getCustomer(int index){
        if(index < 0 || index >= this.getTotal()) {
            System.out.println("查询的信息不存在");
            return null;
        }else{
            return customers[index];
        }
    }

}

界面显示类(框架搭起来,需要补充实现的方法)

import java.util.Scanner;

/**
 * @Author:cgn
 * @Description
 * @date
 */
public class CustomerView {
    public static void main(String[] args) {

    }

    //创建一个最大包含20个客户的数组
    CustomerList customerList = new CustomerList(20);

    //进入主界面的方法
    public void enterMainMenu(){
        Scanner sc = new Scanner(System.in);
        boolean flag = true;
        do{
            System.out.println("**********拼电商客户管理系统************");
            System.out.println();
            System.out.println("1.添加客户");
            System.out.println("2.修改客户");
            System.out.println("3.删除客户");
            System.out.println("4.客户列表");
            System.out.println("5.退  出  ");
            System.out.println();
            System.out.println("请输入(1-5)");

            char input = sc.next().charAt(0);//没有校验,需要添加方法或类进行处理
            switch (input){
                case '1':
                    break;
                case '2':
                    break;
                case '3':
                    break;
                case '4':
                    break;
                case '5':
                    break;
                default:
                    break;
            }

        }while(flag);

        sc.close();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值