您的位置:首页 > 其它

简易的客户管理系统,实现用户信息的录入及查询!!!

2018-09-17 20:23 483 查看
package CustomerManagementSystem;

public class Customer {// 描述客户对象信息类
//描述客户信息
private String name;
private String sex;
private String phone;
//默认构造函数
public Customer() {
super();
}
//利用构造函数对对象属性进行初始化
public Customer(String name, String sex, String phone) {
super();
this.name = name;
this.sex = sex;
this.phone = phone;
}
//设置每个属性的get,set方法
public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setSex(String sex) {
this.sex = sex;
}

public String getSex() {
return sex;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getPhone() {
return phone;
}
//获取信息
public String getInfo() {
return name + "\t\t" + sex + "\t\t" + phone;
}
}
package CustomerManagementSystem;

public class CustomerService {
//声明一个数组
private Customer[] cust;
int total = 0;//记录真实存储的客户人数

public CustomerService(int allTotal) {
cust = new Customer[allTotal];
}

//添加方法
public boolean addCustomer(Customer cus) {
if(total<cust.length) {
cust[total] = cus;
total++;
return true;
}else
return false;
}
//查看客户
public Customer[] getAllCustomer() {
Customer [] newCus = new Customer[total];
for(int i = 0;i<total;i++) {
newCus[i]=cust[i];
}
return newCus;
}
}
package CustomerManagementSystem;

import java.util.Scanner;

public class CustomerView {
Scanner in = new Scanner(System.in);
CustomerService cs = new CustomerService(10);

public void menu() {
boolean flag = true;
while (flag) {
System.out.println("请选择操作: 1.添加客户    2.查看客户    3.退出");
int action = in.nextInt();
switch (action) {
case 1:
add();
break;
case 2:
find();
break;
case 3:
System.out.println("是否退出?(Y/N)");
String s = in.next();
if ("Y".equals(s))
flag = false;
}
}
}

private void add() {
System.out.println("请输入姓名:");
String name = in.next();
System.out.println("请输入性别:");
String sex = in.next();
System.out.println("请输入电话号码:");
String phone = in.next();
Customer cus = new Customer(name, sex, phone);
if (cs.addCustomer(cus))
System.out.println("添加成功");
else
System.out.println("添加失败");
}

public void find() {
Customer[] cust = cs.getAllCustomer();
System.out.println("编号\t\t姓名\t\t性别\t\t电话");
for (int i = 0; i < cust.length; i++) {
System.out.println((i + 1) + "\t\t" + cust[i].getInfo());
}
}

public static void main(String[] args) {
CustomerView cv = new CustomerView();
cv.menu();
}
}

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐