实战项目、拼电商客户管理系统
模拟实现一个基于文本界面的《拼电商客户管理系统》进一步掌握编程技巧和调试技巧,熟悉面向对象编程主要涉及以下知识点:
>类结构的使用:属性、方法及构造器
>对象的创建与使用
>类的封装性声明和使用数组
>数组的插了.删除和替换
>关键字的使用: this
public class Customer1 {
//属性
private String name;
private char gender;
private int age;
private String phone;
private String email;
//构造器
public Customer1(){
}
public Customer1(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 int getAge() {
return age;
}
public char getGender() {
return gender;
}
public String getPhone() {
return phone;
}
public String getEmail() {
return email;
}
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setGender(char gender) {
this.gender = gender;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setEmail(String email) {
this.email = email;
}
}
/**
* 。CustomerList为Customer对象的管理模块,内部使用数组管理一组Customer对象
*/
public class CustomerList {
private Customer1[] customer1s;//用来保存客户对象数组
private int total;//记录已保存客户对象的数量
//方法
/**
* 用途:构造器,用来初始化customer的数组
* 参数:total Customer:指定customers数组的最大空间
* @param totalCustomer
*/
public CustomerList(int totalCustomer){
customer1s = new Customer1[totalCustomer];
}
/**
*用途:将参数customer添加组中最后一个客户对象记录之后
* 参数
* @param customer 指定要添加的客户对象
* @return添加成功返回true:false表示数组已满,无法添加
*/
public boolean addCustomer(Customer1 customer){
if(total<customer1s.length){
customer1s[total] =customer;
total++;
return true;
}
return false;
}
/**
* 用途: 用参数cust换数组中由index指定的对象 [
* @param index 指定所替换对象在数组中的位置,从0开始
* 参数: customer指定警换的新客户对象
* @param cust
* @return 换成功返回true; false表示索引无效,无法替换
*/
public boolean replaceCustomer(int index, Customer1 cust){
if (index >= 0&&index<total){
customer1s[index] = cust;
return true;
}
return false;
}
/**
* 用途: 从数组中删除参数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++){
customer1s[i] = customer1s[i+1];
}
//将有效数据最后一个位置置空
customer1s [--total]= null;
return true;
}
/**
* 用途:返回数组中记录的所有客户对象
*
* @return Customer[] 数组中包含了当前所有客户对象,该数组长度与对象个数相同。
*/
public Customer1[] getAllCustomers(){
Customer1[] custs = new Customer1[total];
for(int i = 0;i<custs.length;i++){
custs[i] = customer1s[i];
}
return custs;
}
/**
* 用途: 返回参数index指定索引位置的客户对象记录
* @param index 参数: index指定所要获取的客户在数组中的索引位置,从0 开刻
* @return 封装了客户信息的Customer对象
*/
public Customer1 getCustomer(int index){
if(index < 0 ||index>=total){
return null;
}else{
return customer1s[index];
}
}
/**
* 获取客户列表的数量
* @return total
*/
public int getTotal(){
return total;
}
}
public class CustomerView {
CustomerList customerList = new CustomerList(16);
public void enterMainMenu(){
Boolean loopFlag = true;
//显示桌面
while(true){
System.out.println("——————————————————————拼电商客户管理系统——————————————————————");
System.out.println(" 1 添 加 客 户");
System.out.println(" 2 修 改 客 户");
System.out.println(" 3 删 除 客 户");
System.out.println(" 4 客 户 列 表");
System.out.println(" 5 退 出");
char key = CMUtility.re
switch(key){
case 1:
break;
case 2:
break;
case 3:
break;
}
}
}
private void modifyCustomer(){
}
private void deleteCustomer(){
}
private void listAllCustomers(){
}
public static void main(String[] args){
}
}