利用java實(shí)現(xiàn)一個(gè)客戶(hù)信息管理系統(tǒng)
用博客記錄我自學(xué)的點(diǎn)點(diǎn)滴滴
類(lèi)圖:

Customer類(lèi):
public class Customer {
/**
* @name 客戶(hù)姓名
* @sex 性別
* @age 年齡
* @phone 電話(huà)號(hào)碼
* @email 郵箱
*/
private String name;
private String sex;
private int age;
private String phone;
private String email;
public Customer(){};
public Customer(String name,String sex,int age,String phone,String email){
this.name=name;
this.sex=sex;
this.age=age;
this.phone=phone;
this.email=email;
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name=name;
}
public String getSex(){
return this.sex;
}
public void setSex(String sex){
this.sex=sex;
}
public String getPhone(){
return phone;
}
public void setPhone(String phone){
this.phone=phone;
}
public int getAge(){
return this.age;
}
public void setAge(int age){
this.age=age;
}
public String getEmail(){
return this.email;
}
public void setEmail(String email){
this.email=email;
}
}
CustomerList 類(lèi):
public class CustomerList {
private Customer [] customers;
private static int total = 0;
/**
* 構(gòu)造器初始化對(duì)象數(shù)組
* @param totalCustmoers 客戶(hù)的總數(shù)
*/
public CustomerList(int totalCustmoers){
customers = new Customer[totalCustmoers];
}
/**
* 增加客戶(hù)
* @param customer 客戶(hù)
* @return 返回是否添加成功
*/
public boolean addCustomer(Customer customer){
if(customer!=null&&total<customers.length)
{customers[total]=customer;
total++;
return true;}
else
{ return false;}
}
/**
*替換
* @param index 指定的客戶(hù)的編號(hào)
* @param cust 修改的客戶(hù)
* @return 返回是否修改成功
*/
public boolean replaceCustomer(int index,Customer cust){
if(index>=0 && index <total )
{
customers[index]=cust;return true;
}
else
{
return false;
}
}
/**
*刪除客戶(hù)
* @param index 指定的客戶(hù)的編號(hào)
* @return 返回是否刪除成功
*/
public boolean deleteCustomer(int index){
if(index<customers.length)
{
for(int i=index;i<total-1;i++)
{
customers[i]=customers[i+1];/**把數(shù)據(jù)往前挪動(dòng)*/
}
customers[total-1]=null;
total--;/**存儲(chǔ)的數(shù)據(jù)的總數(shù)-1*/
return true;
}
else
{
return false;
}
}
/**
* 展現(xiàn)客戶(hù)的信息
* @param index
* @return 返回客戶(hù)
*/
public Customer getCustomer(int index){
if(index>=0 && index<total)
{return customers[index];}
else {
return null;
}
}
/**
* 獲取所有的客戶(hù)
* @return 客戶(hù)
*/
public Customer[] getAllCustomers(){
Customer [] cust = new Customer[total];/**新建一個(gè)數(shù)組來(lái)接收原數(shù)組的數(shù)據(jù)*/
for(int i=0;i<total;i++){
cust[i]=customers[i];
}
return cust;
}
/**
* 得到客戶(hù)的總數(shù)
* @return
*/
public int getTotal(){
return total;
}
}
CustomerVIew類(lèi):
public class CustomerView {
private CustomerList customerList = new CustomerList(10);
/**
* 顯示主菜單
*/
public void enterMainMenu(){
while(true)
{System.out.println("-------------------客戶(hù)信息管理軟件-------------------");
System.out.println("1 "+"添加客戶(hù)");
System.out.println("2 "+"修改客戶(hù)");
System.out.println("3 "+"刪除客戶(hù)");
System.out.println("4 "+"客戶(hù)列表");
System.out.println("5 "+"退 出");
System.out.println("-----------------------------------------------------");
Scanner input = new Scanner(System.in);
int op = input.nextInt();
switch(op)
{
case 1 :this.addNewCustomer();break;
case 2 :this.modifyCustomer();break;
case 3 :this.deleteCustomer();break;
case 4 :this.listAllCustomers();break;
case 5 :System.exit(0);break;
default:
System.out.println("重新選擇功能");break;
}
}
}
/**
* 增加客戶(hù)
*/
private void addNewCustomer(){
/**
* 從鍵盤(pán)處接收客戶(hù)數(shù)據(jù)
*/
System.out.println("-------------------添加客戶(hù)-------------------");
Scanner input = new Scanner(System.in);
System.out.println("姓名:");
String name = input.next();
System.out.println("性別:");
String sex=input.next();
System.out.println("年齡:");
int age = input.nextInt();
System.out.println("電話(huà)號(hào)碼:");
String phone = input.next();
System.out.println("電子郵箱:");
String email = input.next();
/**
* 對(duì)客戶(hù)數(shù)據(jù)進(jìn)行封裝
*/
Customer person = new Customer(name,sex,age,phone,email);
Boolean flag=customerList.addCustomer(person);
if(flag)
{
System.out.println("-------------------添加成功-------------------");
}
else
{
System.out.println("-------------------添加失敗-------------------");
}
}
/**
* 修改客戶(hù)信息
*/
private void modifyCustomer(){
System.out.println("-------------------修改客戶(hù)-------------------");
System.out.println("要修改的客戶(hù)id:");
Scanner input = new Scanner(System.in);
int number = input.nextInt();
Customer customer = customerList.getCustomer(number);
System.out.println("姓名:"+customer.getName());
String name = CMUtility.readString(5,customer.getName());
System.out.println("性別:"+customer.getSex());
String sex = CMUtility.readString(5,customer.getSex());
System.out.print("年齡(" + customer.getAge() + "):");
int age = CMUtility.readInt(customer.getAge());
System.out.print("電話(huà)(" + customer.getPhone() + "):");
String phone = CMUtility.readString(13, customer.getPhone());
System.out.print("郵箱(" + customer.getEmail() + "):");
String email = CMUtility.readString(15, customer.getEmail());
/**得到新的客戶(hù)數(shù)據(jù)*/
customer = new Customer(name,sex,age,phone,email);
Boolean flag = customerList.replaceCustomer(number,customer);
if(flag)
{
System.out.println("-------------------修改成功-------------------");
}
else
{
System.out.println("-------------------修改失敗-------------------");
}
}
/**
* 刪除客戶(hù)
*/
private void deleteCustomer(){
System.out.println("-------------------刪除客戶(hù)-------------------");
System.out.println("要?jiǎng)h除的客戶(hù)id:");
Scanner input = new Scanner(System.in);
int number = input.nextInt();
while(true){
System.out.println("退出(-1)");
if(number>=0 && number<customerList.getTotal())
{
System.out.println("找到指定客戶(hù)");
}
else if(number==-1)
{
return;
}
else
{
System.out.println("輸入錯(cuò)誤");break;
}}
System.out.println("是否確認(rèn)刪除該客戶(hù)?Y/N");
String ch = input.next();
char o = ch.charAt(0);
if(o=='Y')
{
boolean flag = customerList.deleteCustomer(number);
if(flag){
System.out.println("-------------------刪除成功-------------------");
}
else
{
System.out.println("-------------------刪除失敗-------------------");
}
}
else{
return;
}
}
/**
* 獲取客戶(hù)列表
*/
private void listAllCustomers(){
Customer [] customer=customerList.getAllCustomers();
if(customer.length==0)
{
System.out.println("沒(méi)有任何客戶(hù)數(shù)據(jù)");
}
else{
for(int i=0;i< customer.length;i++)
{
System.out.println("姓名:"+customer[i].getName()+"\t"+"性別"+customer[i].getSex()+"\t"+"年齡:"+customer[i].getAge()+"\t"+"電話(huà)號(hào)碼:"+customer[i].getPhone()+"\t"+"電子郵箱:"+customer[i].getEmail()+"\t");
}
}}
public static void main(String[] args) {
CustomerView co = new CustomerView();
co.enterMainMenu();
}
}
工具類(lèi):
public class CMUtility {
private static Scanner scanner = new Scanner(System.in);
public static String readString(int limit) {
return readKeyBoard(limit, false);
}
public static int readInt(int defaultValue) {
int n;
for (; ; ) {
String str = readKeyBoard(2, true);
if (str.equals("")) {
return defaultValue;
}
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print("數(shù)字輸入錯(cuò)誤,請(qǐng)重新輸入:");
}
}
return n;
}
總結(jié)
到此這篇關(guān)于利用java實(shí)現(xiàn)一個(gè)客戶(hù)信息管理系統(tǒng)的文章就介紹到這了,更多相關(guān)java客戶(hù)信息管理系統(tǒng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- java實(shí)現(xiàn)客戶(hù)管理系統(tǒng)
- Java實(shí)現(xiàn)簡(jiǎn)單客戶(hù)信息管理系統(tǒng)
- Java 實(shí)戰(zhàn)項(xiàng)目之CRM客戶(hù)管理系統(tǒng)的實(shí)現(xiàn)流程
- 詳解Java如何使用集合來(lái)實(shí)現(xiàn)一個(gè)客戶(hù)信息管理系統(tǒng)
- Java實(shí)戰(zhàn)之客戶(hù)信息管理系統(tǒng)
- java實(shí)現(xiàn)客戶(hù)信息管理系統(tǒng)
- java實(shí)現(xiàn)簡(jiǎn)單的客戶(hù)信息管理系統(tǒng)
相關(guān)文章
Java設(shè)計(jì)模式之中介者模式的實(shí)現(xiàn)方式
Java中介者模式是一種行為型設(shè)計(jì)模式,它通過(guò)一個(gè)中介者對(duì)象來(lái)協(xié)調(diào)多個(gè)對(duì)象之間的交互,降低對(duì)象之間的耦合度,提高系統(tǒng)的可維護(hù)性和可擴(kuò)展性。本文將介紹該設(shè)計(jì)模式的原理、使用場(chǎng)景和實(shí)現(xiàn)方法2023-04-04
SpringBoot解決數(shù)據(jù)庫(kù)時(shí)間和返回時(shí)間格式不一致的問(wèn)題
這篇文章主要介紹了SpringBoot解決數(shù)據(jù)庫(kù)時(shí)間和返回時(shí)間格式不一致的問(wèn)題,文章通過(guò)代碼示例和圖文結(jié)合的方式講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)和工作有一定的幫助,需要的朋友可以參考下2024-03-03
Spring Boot項(xiàng)目中定制PropertyEditors方法
在本篇文章里小編給大家分享的是一篇關(guān)于Spring Boot定制PropertyEditors的知識(shí)點(diǎn)內(nèi)容,有需要的朋友們可以參考學(xué)習(xí)下。2019-11-11
解決JDK異常處理No appropriate protocol問(wèn)題
這篇文章主要介紹了解決JDK異常處理No appropriate protocol問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
Mybatis整合達(dá)夢(mèng)數(shù)據(jù)庫(kù)的完整步驟記錄
作為國(guó)產(chǎn)數(shù)據(jù)庫(kù),達(dá)夢(mèng)做的不錯(cuò),提供的遷移工具也相當(dāng)不錯(cuò),下面這篇文章主要給大家介紹了關(guān)于Mybatis整合達(dá)夢(mèng)數(shù)據(jù)庫(kù)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
將下載好的jar包導(dǎo)入到本地maven倉(cāng)庫(kù)中操作
這篇文章主要介紹了將下載好的jar包導(dǎo)入到本地maven倉(cāng)庫(kù)中操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08
Java 訪(fǎng)問(wèn)剪切板(復(fù)制,粘貼)的示例
這篇文章主要介紹了Java 訪(fǎng)問(wèn)剪切板(復(fù)制,粘貼)的示例,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下2020-11-11
Java8中對(duì)于LocalDateTime的序列化和反序列化問(wèn)題
這篇文章主要介紹了Java8中對(duì)于LocalDateTime的序列化和反序列化問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
Java實(shí)現(xiàn)矩陣乘法以及優(yōu)化的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Java實(shí)現(xiàn)矩陣乘法以及優(yōu)化的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02

