使用Java怎么制作一個客戶信息管理軟件

這篇文章給大家介紹使用Java怎么制作一個客戶信息管理軟件,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷推廣、網(wǎng)站重做改版、鼓樓網(wǎng)站定制設(shè)計、自適應品牌網(wǎng)站建設(shè)、成都h5網(wǎng)站建設(shè)、電子商務商城網(wǎng)站建設(shè)、集團公司官網(wǎng)建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應式網(wǎng)頁設(shè)計等建站業(yè)務,價格優(yōu)惠性價比高,為鼓樓等各大城市提供網(wǎng)站開發(fā)制作服務。

項目簡介

模擬實現(xiàn)基于文本界面的《客戶信息管理軟件》。

該軟件能夠?qū)崿F(xiàn)對客戶對象的插入、修改和刪除(用數(shù)組實現(xiàn)),并能夠打印客戶明細表。

涉及的知識點

  • 類結(jié)構(gòu)的使用:屬性、方法及構(gòu)造器

  • 對象的創(chuàng)建與使用

  • 類的封裝性

  • 聲明和使用數(shù)組

  • 數(shù)組的插入、刪除和替換

  • 關(guān)鍵字的使用:this

項目需求:

  • 每個客戶的信息被保存在Customer對象中。

  • 以一個Customer類型的數(shù)組來記錄當前所有的客戶。

  • 每次“添加客戶”(菜單1)后,客戶(Customer)對象被添加到數(shù)組中。

  • 每次“修改客戶”(菜單2)后,修改后的客戶(Customer)對象替換數(shù)組中原對象。

  • 每次“刪除客戶”(菜單3)后,客戶(Customer)對象被從數(shù)組中清除。

  • 執(zhí)行“客戶列表 ”(菜單4)時,將列出數(shù)組中所有客戶的信息。

項目菜單展示

主菜單界面

             -----------------客戶信息管理軟件-----------------

                                     1 添 加 客 戶
                                     2 修 改 客 戶
                                     3 刪 除 客 戶
                                     4 客 戶 列 表
                                     5 退           出

                                     請選擇(1-5):_

添加客戶界面

                   請選擇(1-5):1

---------------------添加客戶---------------------
姓名:佟剛
性別:男
年齡:35
電話:010-56253825
郵箱:tongtong@atguigu.com
---------------------添加完成---------------------

修改客戶界面

請選擇(1-5):2

---------------------修改客戶---------------------
請選擇待修改客戶編號(-1退出):1
姓名(佟剛):<直接回車表示不修改>
性別(男):
年齡(35):
電話(010-56253825):
郵箱(tongtong@163.com):tongg@123.com
---------------------修改完成---------------------

刪除客戶界面

請選擇(1-5):3

---------------------刪除客戶---------------------
請選擇待刪除客戶編號(-1退出):1
確認是否刪除(Y/N):y
---------------------刪除完成---------------------

客戶列表界面

請選擇(1-5):4

---------------------------客戶列表---------------------------
編號  姓名       性別    年齡   電話                   郵箱
 1    佟剛         男        45     010-56253825   tong@abc.com
 2    封捷         女        36     010-56253825   fengjie@ibm.com
 3    雷豐陽     男        32      010-56253825   leify@163.com
-------------------------客戶列表完成-------------------------

項目設(shè)計結(jié)構(gòu)

軟件由以下模塊組成

使用Java怎么制作一個客戶信息管理軟件

  • CustomerView為主模塊,負責菜單的顯示和處理用戶操作

  • CustomerList為Customer對象的管理模塊,內(nèi)部用數(shù)組管理一組Customer對象,并提供相應的添加、修改、刪除和遍歷方法,供CustomerView調(diào)用

  • Customer為實體對象,用來封裝客戶信息

軟件內(nèi)存調(diào)用簡圖

使用Java怎么制作一個客戶信息管理軟件

enterMainMenu方法的調(diào)用圖

使用Java怎么制作一個客戶信息管理軟件

項目實現(xiàn)

項目采用MVC設(shè)計結(jié)構(gòu),對項目的包結(jié)構(gòu)進行分層管理

項目包結(jié)構(gòu):

使用Java怎么制作一個客戶信息管理軟件

  1. bean包下存放Customer類

    存放客戶對象,設(shè)置客戶屬性實現(xiàn)get set 方法,提供構(gòu)造器

  2. service包存放CustomerList類

    用于實現(xiàn)增刪改查等功能

  3. util包下存放通用抽取類CMUtility

    用于實現(xiàn)鍵盤讀入操作

  4. view包下存放界面顯示類CustomerView

    用于在操作臺顯示界面進行交互操作

項目類設(shè)計

通用鍵盤訪問類CMUtility設(shè)計

設(shè)計通用的鍵盤讀取方法,將所有的鍵盤讀取操作進行封裝

package com.bruce.project.project02.util;

import java.util.Scanner;

/**
 * CMUtility工具類: 將不同的功能封裝為方法,就是可以直接通過調(diào)用方法使用它的功能,而無需考慮具體的功能實現(xiàn)細節(jié)。
 */
public class CMUtility {
    private static Scanner scanner = new Scanner(System.in);

    /**
     * 用于界面菜單的選擇。該方法讀取鍵盤,如果用戶鍵入’1’-’5’中的任意字符,則方法返回。返回值為用戶鍵入字符。
     */
    public static char readMenuSelection() {
        char c;
        for (;;) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2' && c != '3' && c != '4' && c != '5') {
                System.out.print("選擇錯誤,請重新輸入:");
            } else
                break;
        }
        return c;
    }

    /**
     * 從鍵盤讀取一個字符,并將其作為方法的返回值。
     */
    public static char readChar() {
        String str = readKeyBoard(1, false);
        return str.charAt(0);
    }

    /**
     * 從鍵盤讀取一個字符,并將其作為方法的返回值。 如果用戶不輸入字符而直接回車,方法將以defaultValue 作為返回值。
     */
    public static char readChar(char defaultValue) {
        String str = readKeyBoard(1, true);
        return (str.length() == 0) ? defaultValue : str.charAt(0);
    }

    /**
     * 從鍵盤讀取一個長度不超過2位的整數(shù),并將其作為方法的返回值。
     */
    public static int readInt() {
        int n;
        for (;;) {
            String str = readKeyBoard(2, false);
            try {
                n = Integer.parseInt(str);
                break;
            } catch (NumberFormatException e) {
                System.out.print("數(shù)字輸入錯誤,請重新輸入:");
            }
        }
        return n;
    }

    /**
     * 從鍵盤讀取一個長度不超過2位的整數(shù),并將其作為方法的返回值。 如果用戶不輸入字符而直接回車,方法將以defaultValue 作為返回值。
     */
    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ù)字輸入錯誤,請重新輸入:");
            }
        }
        return n;
    }

    /**
     * 從鍵盤讀取一個長度不超過limit的字符串,并將其作為方法的返回值。
     */
    public static String readString(int limit) {
        return readKeyBoard(limit, false);
    }

    /**
     * 從鍵盤讀取一個長度不超過limit的字符串,并將其作為方法的返回值。 如果用戶不輸入字符而直接回車,方法將以defaultValue 作為返回值。
     */
    public static String readString(int limit, String defaultValue) {
        String str = readKeyBoard(limit, true);
        return str.equals("") ? defaultValue : str;
    }

    /**
     * 用于確認選擇的輸入。該方法從鍵盤讀取‘Y’或’N’,并將其作為方法的返回值。
     */
    public static char readConfirmSelection() {
        char c;
        for (;;) {
            String str = readKeyBoard(1, false).toUpperCase();
            c = str.charAt(0);
            if (c == 'Y' || c == 'N') {
                break;
            } else {
                System.out.print("選擇錯誤,請重新輸入:");
            }
        }
        return c;
    }

    private static String readKeyBoard(int limit, boolean blankReturn) {
        String line = "";

        while (scanner.hasNextLine()) {
            line = scanner.nextLine();
            if (line.length() == 0) {
                if (blankReturn)
                    return line;
                else
                    continue;
            }

            if (line.length() < 1 || line.length() > limit) {
                System.out.print("輸入長度(不大于" + limit + ")錯誤,請重新輸入:");
                continue;
            }
            break;
        }

        return line;
    }
}
客戶類Customer類設(shè)計

對用戶的屬性進行封裝,提供空參數(shù)構(gòu)造器和帶有所有參數(shù)的構(gòu)造器

package com.bruce.project.project02.bean;

public class Customer {
    private String name;
    private char gender;
    private int age;
    private String phone;
    private String email;

    public Customer() {

    }

    public Customer(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 void setName(String name) {
        this.name = name;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPhone() {
        return phone;
    }

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

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * 
     * @Description 顯示用戶信息的方法
     * @author Bruce
     * @return String
     */
    public String getDetails() {
        return name + "\t" + gender + "\t" + age + "\t\t" + phone + "\t" + email;
    }

}
客戶操作類CustomerList類設(shè)計

設(shè)計項目中客戶的添加、刪除、修改、顯示等功能

package com.bruce.project.project02.service;

import com.bruce.project.project02.bean.Customer;

public class CustomerList {
    private Customer[] customers;
    private int total = 0;

    /**
     * 構(gòu)造器,用來初始化customers數(shù)組
     * 
     * @param totalCustomer
     */
    public CustomerList(int totalCustomer) {

        customers = new Customer[totalCustomer];
    }

    /**
     * 
     * @Description 添加客戶的方法
     * @author Bruce
     * @param customer
     * @return boolean 添加成功返回true;false表示數(shù)組已滿,無法添加
     */
    public boolean addCustomer(Customer customer) {
        if (total >= customers.length) {
            return false;
        }
        customers[total++] = customer;
        return true;
    }

    /**
     * 
     * @Description 修改客戶信息的方法
     * @author Bruce
     * @param index
     *            指定所替換對象在數(shù)組中的位置,從0開始
     * @param cust
     * @return boolean 替換成功返回true;false表示索引無效,無法替換
     * 
     */
    public boolean repalceCustomer(int index, Customer cust) {
        if (index < 0 || index >= total) {
            return false;
        }
        customers[index] = cust;
        return true;
    }

    /**
     * 
     * @Description 刪除客戶信息的方法
     * @author Bruce
     * @param index 指定所刪除對象在數(shù)組中的索引位置,從0開始
     * @return boolean 刪除成功返回true;false表示索引無效,無法刪除
     */
    public boolean deleteCustomer(int index) {
        if (index < 0 || index >= total) {
            return false;
        }
        for (int i = 0; i < total - 1; i++) {
            customers[i] = customers[i + 1];
        }
        customers[--total] = null;

        return true;
    }

    /**
     * 
     * @Description 獲取全部客戶信息
     * @author Bruce
     * @return Customer[]數(shù)組中包含了當前所有客戶對象,該數(shù)組長度與對象個數(shù)相同。
     */
    public Customer[] getAllCustomers() {
        Customer[] custs = new Customer[total];
        for (int i = 0; i < total; i++) {
            custs[i] = customers[i];
        }
        return custs;
    }

    /**
     * 
     * @Description TODO
     * @author Bruce
     * @param index
     * @return 封裝了客戶信息的Customer對象
     */
    public Customer getCustomer(int index) {
        if (index < 0 || index >= total) {
            return null;
        }
        return customers[index];
    }

    public int getTotal() {
        return total;
    }

}
客戶顯示界面類CustomerView類設(shè)計

在控制臺顯示的主要界面

package com.bruce.project.project02.view;

import com.bruce.project.project02.bean.Customer;
import com.bruce.project.project02.service.CustomerList;
import com.bruce.project.project02.util.CMUtility;

public class CustomerView {
    private CustomerList customers = new CustomerList(10);

    // 初始建立一個用戶
    public CustomerView() {
        Customer cust = new Customer("張三", '男', 30, "1151511215", "abs@163.com");
        customers.addCustomer(cust);
    }

    /**
     * 
     * @Description 軟件主界面,顯示功能
     * @author Bruce void
     */
    public void enterMainMenu() {
        boolean loopFlag = true;
        do {
            System.out.println("\n-----------------客戶信息管理軟件-----------------\n");
            System.out.println("                   1 添 加 客 戶");
            System.out.println("                   2 修 改 客 戶");
            System.out.println("                   3 刪 除 客 戶");
            System.out.println("                   4 客 戶 列 表");
            System.out.println("                   5 退       出\n");
            System.out.print("                   請選擇(1-5):");

            char key = CMUtility.readMenuSelection();
            System.out.println();

            switch (key) {
            case '1':
                addNewCustomer();
                break;
            case '2':
                modifyCustomer();
                break;
            case '3':
                deleteCustomer();
                break;
            case '4':
                listAllCustomer();
                break;
            case '5':
                System.out.println("是否退出(Y/N):");
                char yn = CMUtility.readConfirmSelection();
                if (yn == 'Y') {
                    loopFlag = false;
                }
                break;

            default:
                break;
            }

        } while (loopFlag);
    }

    /**
     * 
     * @Description 顯示添加用戶界面
     * @author Bruce void
     */
    private void addNewCustomer() {
        System.out.println("---------------------添加客戶---------------------");
        System.out.print("姓名:");
        String name = CMUtility.readString(4);
        System.out.println("性別");
        char gender = CMUtility.readChar();
        System.out.println("年齡");
        int age = CMUtility.readInt();
        System.out.println("電話");
        String phone = CMUtility.readString(15);
        System.out.println("郵箱");
        String email = CMUtility.readString(15);

        Customer cust = new Customer(name, gender, age, phone, email);
        boolean flag = customers.addCustomer(cust);
        if (flag) {
            System.out.println("---------------------添加完成---------------------");
        } else {
            System.out.println("----------------記錄已滿,無法添加-----------------");
        }

    }

    /**
     * 
     * @Description 顯示修改用戶信息界面
     * @author Bruce void
     */
    private void modifyCustomer() {
        System.out.println("---------------------修改客戶---------------------");
        int index = 0;
        Customer cust = null;
        for (;;) {
            System.out.print("請選擇待修改客戶編號(-1退出):");
            index = CMUtility.readInt();
            if (index == -1) {
                return;
            }

            cust = customers.getCustomer(index - 1);
            if (cust == null) {
                System.out.println("無法找到該用戶");
            } else
                break;
        }

        System.out.println("姓名(" + cust.getName() + "):");
        String name = CMUtility.readString(4, cust.getName());

        System.out.println("性別(" + cust.getGender() + "):");
        char gender = CMUtility.readChar(cust.getGender());

        System.out.println("年齡(" + cust.getAge() + "):");
        int age = CMUtility.readInt(cust.getAge());

        System.out.println("電話(" + cust.getPhone() + "):");
        String phone = CMUtility.readString(15, cust.getPhone());

        System.out.println("郵箱(" + cust.getEmail() + "):");
        String email = CMUtility.readString(15, cust.getEmail());

        cust = new Customer(name, gender, age, phone, email);

        boolean flag = customers.repalceCustomer(index - 1, cust);
        if (flag) {
            System.out.println("---------------------修改完成---------------------");
        } else {
            System.out.println("----------無法找到指定客戶,修改失敗--------------");
        }

    }

    /**
     * 
     * @Description 刪除用戶界面
     * @author Bruce void
     */
    private void deleteCustomer() {
        System.out.println("---------------------刪除客戶---------------------");
        int index = 0;
        Customer cust = null;
        for (;;) {
            System.out.println("選擇待刪除客戶的編號(-1退出)");
            index = CMUtility.readInt();
            if (index == -1) {
                return;
            }

            cust = customers.getCustomer(index - 1);
            if (cust == null) {
                System.out.println("無法找到指定客戶");
            } else
                break;

        }
        // 跳出循環(huán)是否刪除
        System.out.println("是否刪除客戶(Y/N)");
        char yn = CMUtility.readChar();
        if (yn == 'N')
            return;

        boolean flag = customers.deleteCustomer(index - 1);
        if (flag) {
            System.out.println("---------------------刪除完成---------------------");
        } else {
            System.out.println("----------無法找到指定客戶,刪除失敗--------------");
        }
    }

    /**
     * 
     * @Description 列出客戶列表
     * @author Bruce void
     */
    private void listAllCustomer() {
        System.out.println("---------------------------客戶列表---------------------------");
        Customer[] custs = customers.getAllCustomers();
        if (custs.length == 0) {
            System.out.println("沒有客戶編號!");

        } else {
            System.out.println("編號\t姓名\t性別\t年齡\t\t電話\t\t郵箱");
            for (int i = 0; i < custs.length; i++) {
                System.out.println((i + 1) + "\t" + custs[i].getDetails());
            }
        }

        System.out.println("-------------------------客戶列表完成-------------------------");

    }

}

軟件調(diào)用類CustomerTest類設(shè)計

package com.bruce.project.project02;

import com.bruce.project.project02.view.CustomerView;

public class CustomerTest {
    public static void main(String[] args) {
        CustomerView cView = new CustomerView();
        cView.enterMainMenu();
    }
}

關(guān)于使用Java怎么制作一個客戶信息管理軟件就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

網(wǎng)頁標題:使用Java怎么制作一個客戶信息管理軟件
分享網(wǎng)址:http://www.muchs.cn/article28/ishgcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、移動網(wǎng)站建設(shè)面包屑導航、搜索引擎優(yōu)化、品牌網(wǎng)站建設(shè)、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作