java客户管理信息系统
时间: 2023-11-24 12:52:17 浏览: 27
Java客户管理信息系统是一个用Java编写的程序,用于管理客户信息。该系统使用JDK1.8作为运行环境,使用IDEA 2020作为开发工具。在该系统中,使用数组来管理一组Customer对象,其中封装了实际用户个数属性total和存放客户对象的数组customers。默认情况下,该系统可以存储十个客户对象信息,但可以通过构造器进行自定义修改。此外,该系统还具备对客户列表进行管理操作的功能方法。
以下是Java客户管理信息系统的基本结构:
```java
public class CustomerList {
private Customer[] customers; // 用于存放客户对象的数组
private int total = 0; // 记录已保存客户对象的数量
/**
* 构造器,用于初始化customers数组
* @param totalCustomer 指定customers数组的最大空间
*/
public CustomerList(int totalCustomer) {
customers = new Customer[totalCustomer];
}
/**
* 将指定的客户添加到数组中
* @param customer 指定要添加的客户
* @return 添加成功返回true,否则返回false
*/
public boolean addCustomer(Customer customer) {
if (total >= customers.length) {
return false;
}
customers[total++] = customer;
return true;
}
/**
* 用参数customer替换数组中由index指定的对象
* @param index 指定所替换对象在数组中的位置,从0开始
* @param customer 指定替换的新客户对象
* @return 替换成功返回true,否则返回false
*/
public boolean replaceCustomer(int index, Customer customer) {
if (index < 0 || index >= total) {
return false;
}
customers[index] = customer;
return true;
}
/**
* 从数组中删除参数index指定索引位置的客户对象
* @param index 指定所删除对象在数组中的位置,从0开始
* @return 删除成功返回true,否则返回false
*/
public boolean deleteCustomer(int index) {
if (index < 0 || index >= total) {
return false;
}
for (int i = index; i < total - 1; i++) {
customers[i] = customers[i + 1];
}
customers[--total] = null;
return true;
}
/**
* 返回数组中记录的所有客户对象
* @return Customer[] 数组中包含了当前所有客户对象,该数组长度与对象个数相同。
*/
public Customer[] getAllCustomers() {
Customer[] custs = new Customer[total];
for (int i = 0; i < total; i++) {
custs[i] = customers[i];
}
return custs;
}
/**
* 返回参数index指定索引位置的客户对象记录
* @param index 指定所要获取的客户在数组中的位置,从0开始
* @return 封装了客户信息的Customer对象
*/
public Customer getCustomer(int index) {
if (index < 0 || index >= total) {
return null;
}
return customers[index];
}
/**
* 返回当前客户的数量
* @return 数组中所包含客户对象的数量
*/
public int getTotal() {
return total;
}
}
```