欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

使用Java怎么制作一個(gè)客戶(hù)信息管理軟件

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

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

項(xiàng)目簡(jiǎn)介

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

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

涉及的知識(shí)點(diǎn)

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

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

  • 類(lèi)的封裝性

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

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

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

項(xiàng)目需求:

  • 每個(gè)客戶(hù)的信息被保存在Customer對(duì)象中。

  • 以一個(gè)Customer類(lèi)型的數(shù)組來(lái)記錄當(dāng)前所有的客戶(hù)。

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

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

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

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

項(xiàng)目菜單展示

主菜單界面

             -----------------客戶(hù)信息管理軟件-----------------

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

                                     請(qǐng)選擇(1-5):_

添加客戶(hù)界面

                   請(qǐng)選擇(1-5):1

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

修改客戶(hù)界面

請(qǐng)選擇(1-5):2

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

刪除客戶(hù)界面

請(qǐng)選擇(1-5):3

---------------------刪除客戶(hù)---------------------
請(qǐng)選擇待刪除客戶(hù)編號(hào)(-1退出):1
確認(rèn)是否刪除(Y/N):y
---------------------刪除完成---------------------

客戶(hù)列表界面

請(qǐng)選擇(1-5):4

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

項(xiàng)目設(shè)計(jì)結(jié)構(gòu)

軟件由以下模塊組成

使用Java怎么制作一個(gè)客戶(hù)信息管理軟件

  • CustomerView為主模塊,負(fù)責(zé)菜單的顯示和處理用戶(hù)操作

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

  • Customer為實(shí)體對(duì)象,用來(lái)封裝客戶(hù)信息

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

使用Java怎么制作一個(gè)客戶(hù)信息管理軟件

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

使用Java怎么制作一個(gè)客戶(hù)信息管理軟件

項(xiàng)目實(shí)現(xiàn)

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

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

使用Java怎么制作一個(gè)客戶(hù)信息管理軟件

  1. bean包下存放Customer類(lèi)

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

  2. service包存放CustomerList類(lèi)

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

  3. util包下存放通用抽取類(lèi)CMUtility

    用于實(shí)現(xiàn)鍵盤(pán)讀入操作

  4. view包下存放界面顯示類(lèi)CustomerView

    用于在操作臺(tái)顯示界面進(jìn)行交互操作

項(xiàng)目類(lèi)設(shè)計(jì)

通用鍵盤(pán)訪問(wèn)類(lèi)CMUtility設(shè)計(jì)

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

package com.bruce.project.project02.util;

import java.util.Scanner;

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

    /**
     * 用于界面菜單的選擇。該方法讀取鍵盤(pán),如果用戶(hù)鍵入’1’-’5’中的任意字符,則方法返回。返回值為用戶(hù)鍵入字符。
     */
    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("選擇錯(cuò)誤,請(qǐng)重新輸入:");
            } else
                break;
        }
        return c;
    }

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

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

    /**
     * 從鍵盤(pán)讀取一個(gè)長(zhǎng)度不超過(guò)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ù)字輸入錯(cuò)誤,請(qǐng)重新輸入:");
            }
        }
        return n;
    }

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

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

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

    /**
     * 用于確認(rèn)選擇的輸入。該方法從鍵盤(pán)讀取‘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("選擇錯(cuò)誤,請(qǐng)重新輸入:");
            }
        }
        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("輸入長(zhǎng)度(不大于" + limit + ")錯(cuò)誤,請(qǐng)重新輸入:");
                continue;
            }
            break;
        }

        return line;
    }
}
客戶(hù)類(lèi)Customer類(lèi)設(shè)計(jì)

對(duì)用戶(hù)的屬性進(jìn)行封裝,提供空參數(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 顯示用戶(hù)信息的方法
     * @author Bruce
     * @return String
     */
    public String getDetails() {
        return name + "\t" + gender + "\t" + age + "\t\t" + phone + "\t" + email;
    }

}
客戶(hù)操作類(lèi)CustomerList類(lèi)設(shè)計(jì)

設(shè)計(jì)項(xiàng)目中客戶(hù)的添加、刪除、修改、顯示等功能

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)造器,用來(lái)初始化customers數(shù)組
     * 
     * @param totalCustomer
     */
    public CustomerList(int totalCustomer) {

        customers = new Customer[totalCustomer];
    }

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

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

    /**
     * 
     * @Description 刪除客戶(hù)信息的方法
     * @author Bruce
     * @param index 指定所刪除對(duì)象在數(shù)組中的索引位置,從0開(kāi)始
     * @return boolean 刪除成功返回true;false表示索引無(wú)效,無(wú)法刪除
     */
    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 獲取全部客戶(hù)信息
     * @author Bruce
     * @return Customer[]數(shù)組中包含了當(dāng)前所有客戶(hù)對(duì)象,該數(shù)組長(zhǎng)度與對(duì)象個(gè)數(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 封裝了客戶(hù)信息的Customer對(duì)象
     */
    public Customer getCustomer(int index) {
        if (index < 0 || index >= total) {
            return null;
        }
        return customers[index];
    }

    public int getTotal() {
        return total;
    }

}
客戶(hù)顯示界面類(lèi)CustomerView類(lèi)設(shè)計(jì)

在控制臺(tái)顯示的主要界面

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);

    // 初始建立一個(gè)用戶(hù)
    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-----------------客戶(hù)信息管理軟件-----------------\n");
            System.out.println("                   1 添 加 客 戶(hù)");
            System.out.println("                   2 修 改 客 戶(hù)");
            System.out.println("                   3 刪 除 客 戶(hù)");
            System.out.println("                   4 客 戶(hù) 列 表");
            System.out.println("                   5 退       出\n");
            System.out.print("                   請(qǐng)選擇(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 顯示添加用戶(hù)界面
     * @author Bruce void
     */
    private void addNewCustomer() {
        System.out.println("---------------------添加客戶(hù)---------------------");
        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("----------------記錄已滿,無(wú)法添加-----------------");
        }

    }

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

            cust = customers.getCustomer(index - 1);
            if (cust == null) {
                System.out.println("無(wú)法找到該用戶(hù)");
            } 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("----------無(wú)法找到指定客戶(hù),修改失敗--------------");
        }

    }

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

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

        }
        // 跳出循環(huán)是否刪除
        System.out.println("是否刪除客戶(hù)(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("----------無(wú)法找到指定客戶(hù),刪除失敗--------------");
        }
    }

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

        } else {
            System.out.println("編號(hào)\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("-------------------------客戶(hù)列表完成-------------------------");

    }

}

軟件調(diào)用類(lèi)CustomerTest類(lèi)設(shè)計(jì)

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怎么制作一個(gè)客戶(hù)信息管理軟件就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

網(wǎng)頁(yè)標(biāo)題:使用Java怎么制作一個(gè)客戶(hù)信息管理軟件
分享網(wǎng)址:http://www.chinadenli.net/article28/ishgcp.html

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

廣告

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

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