1.软件设计结构
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/66373733f3849b1f1c103e4aee35c682.png)
- CustomerView为主模块,负责菜单的显示和处理用户操作
- CustomerList为Customer对象的管理模块,内部用数组管理一组Customer对象,并提供相应的添加、修改、删除、和遍历方法,供CustomerView调用
- Customer为实体对象,用来封装客户信息
2.代码
package bean;
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;
}
}
package service;
import bean.Customer;
public class CustomerList {
private Customer[] customers;
private int total = 0;
public CustomerList(int totalCustomer) {
customers = new Customer[totalCustomer];
}
public boolean addCustomer(Customer customer) {
if (total >= customers.length) {
return false;
}
customers[total] = customer;
total++;
return true;
}
public boolean replaceCustomer(int index, Customer cust) {
if (index < 0 || index >= total) {
return false;
}
customers[index] = cust;
return true;
}
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 - 1] = null;
total--;
return true;
}
public Customer[] getAllCustomers() {
Custo