java基础项目练习二-客户信息管理程序,实现基本的增删改查

练习基本的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(
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值