练习基本的MVC设计模式,创建customer类,提供基本属性和对应的存取方法
package bean;
public class Customer {
private String name;
private int age;
private char gender;
private String phone;
private String email;
public Customer() {
}
public Customer(String name, int age, char gender, String phone, String email) {
this.name = name;
this.age = age;
this.gender = gender;
this.phone = phone;
this.email = email;
}
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 char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
public String getemail() {
return email;
}
public void setemail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void getInfo() {
System.out.println("客户姓名: " + name);
System.out.println("客户性别: " + gender);
System.out.println("客户年龄: " + age);
System.out.println("客户电话: " + phone);
System.out.println("客户邮箱: " + email);
}
}
创建customerList类,提供对象数组的增删改查方法
package controller;
import bean.Customer;
public class CustomerList {
private int total = 0;
private int limite = 9999;
private Customer[] customers;
public CustomerList() {
}
public boolean addCustomer(Customer customer) {
total++;
Customer[] customersTemp = new Customer[total];
customersTemp[total - 1] = customer;
for (int i = 0; i < customersTemp.length - 1; i++) {
customersTemp[i] = customers[i];
}
customers = customersTemp;
if(total >= 0 && total <= limite) {
return true;
}else{
return false;
}
}
public boolean replaceCustomer(int index,Customer customer) {
if(index < 0 || index > total - 1) {
return false;
}else {
customers[index] = customer;
return true;
}
}
public boolean deleteCustomer(int index) {
if(index < 0 || index > total - 1) {
return false;
}else {
total--;
if(total >= 0) {
Customer[] customersTemp = new Customer[total];
for (int i = 0; i < total; i++) {
if(i < index) {
customersTemp[i] = customers[i];
}else {
customersTemp[i] = customers[i + 1];
}
}
customers = customersTemp;
return true;
}else {
return false;
}
}
}
public int getTotal() {
return total;
}
public Customer[] getAllcustomers(