学生管理系统及客户信息管理软件做题思路及代码

  • 1.学生管理系统

做题步骤:

①建立学生类(存储信息利用set/get方法)

②建立测试类

1.建立页面(把各个功能填写在上面)

 2.建立选项(利用switch把各个选项弄出,具体功能稍后再建立)

3.根据不同选项建立不同方法

建议:先把添加学生功能建立,依次再建立查看所以学生功能,最后建立删除和修改学习功能(每个功能建立后应依次验证)

 

 2.客户管理信息系统

四个类:

——①客户信息类

——②存储客户信息类的操作包

——③工具包(具体功能细节暂不研究) 

——④测试类(也是主页面)

CustomerList的类要用

private Customer[] customers;——信息类的调用        
private int total;——记录保存数组的个数

具体代码如下

Customer类的属性填写后利用Idea的公式生成构造函数和SET/GET函数

/**
 * @auther shkstrat
 * @create 2021-08-05 9:55
 */
public class Customer {
    private String name;// 姓名
    private char gender;// 性别
    private int age;// 年龄
    private String phone;// 电话
    private String email;// 邮箱

    public Customer() {

    }

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

    public String getName() {
        return name;
    }

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

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

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

    public String getPhone() {
        return phone;
    }

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

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
    public String info(){
        return name + "\t" + gender + "\t" + age + "\t" + phone + "\t" + email;
    }
}

CustomerList利用数组的索引值来进行添加,修改,删除功能,具体代码如下

public class CustomerList {
    private Customer[] customers;
    private int total;

    public CustomerList(int totalCustomer) {
        customers = new Customer[totalCustomer];
        total = 0;
    }


    public boolean addCustomer(Customer customer) {//添加指定的客户到数组中
        if (customer != null && total < customers.length) {
            customers[total++] = customer;
            return true;
        }
        return false;
    }

    public boolean replaceCustomer(int index, Customer cust) {//替换指定索引位置上的数组元素
        if (index >= 0 && index < total) {
            customers[index] = cust;
            return true;
        }
        return false;
    }

    public boolean deleteCustomer(int index) {//删除指定索引位置上的元素

        if (index >= 0 && index < total) {
            for (int i = index; i < total - 1; i++) {
                customers[i] = customers[i + 1];
                customers[--total]=null;
            }
            return true;
        }
        return false;

    }

    public Customer[]getAllCustomers(){//获取customers对象构成的数组
        Customer[]custs=new Customer[total];
        for(int i =0;i<custs.length;i++){
            custs[i]=customers[i];
        }
        return  custs;
    }

     public Customer getCustomer(int index){ //返回指定索引位置上的Customer
        if(index >=0&&index<total ){
            return   customers[index];
        }
        return  null;
     }

     public int getTotal(){
        return  total;
     }

}

 CustomerView——主页面(具体代码不书写)

容易错的点:

首先创建一个对象,目的:可以调用它的构造方法

private CustomerList custList = new CustomerList(10);

 添加学生信息类时

Customer customer =new Customer(name,gender,age,phone,email);

        boolean flag =custList.addCustomer(customer);

 修改时

cust=new Customer(name,gender,age,phone,email);

            boolean flag=custList.replaceCustomer(index-1,cust);
            if(flag){
                System.out.println("-------------修改改成-------------");
                break;
            }else{
                System.out.println("-------------无法找到指定用户-------------");
            }

        }

删除时

System.out.print("请选择待删除客户编号(-1退出):");
               index =CMUtility.readInt();



 System.out.print("确认是否删除(Y/N)");
        char deleteOrNot = CMUtility.readConfirmSelection();
        if (deleteOrNot == 'Y'){
                boolean flag =custList.deleteCustomer(index-1);
                if(flag){
                    System.out.println("---------------------删除完成---------------------");
                }else{
                    System.out.println("---------------------删除失败---------------------");
                }
        }else{
            return;
        }

具体操作页面具体如下

客户主页面

功能一:添加用户

 

 --------------------------------------------------------------------------------------------------------------------------------

功能二:修改用户

 

 ------------------------------------------------------------------------------------------------------------------

功能三:删除用户

 ------------------------------------------------------------------------------------------------------------------

 功能四:查看用户列表

 

----------------------------------------------------------------------------------------------------------------- 

功能五:退出

猜你喜欢

转载自blog.csdn.net/m0_59619191/article/details/119422905