最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

新手易懂的Java客戶管理小項(xiàng)目

 更新時(shí)間:2021年11月26日 09:04:33   作者:鐵甲小寶同學(xué)  
本篇文章是作為一個(gè)很適合新手閱讀的初級(jí)小項(xiàng)目,客戶管理,它主要實(shí)現(xiàn)數(shù)據(jù)庫的增刪查改操作,管理每位客戶的不同信息,如果你也是開始學(xué)Java不久,這篇文章將很適合你

每日一語:花開蝶自來?。?!

前言:隨著我把狂神的Java的基礎(chǔ)篇看完,我覺得我應(yīng)該是把Java的基礎(chǔ)應(yīng)該沒什么問題了,所以我決定找一個(gè)小項(xiàng)目寫寫,所以我就看了尚硅谷的基礎(chǔ)小項(xiàng)目,不看不知道,一看嚇一跳,我發(fā)現(xiàn)我雖然看完了基礎(chǔ)的部分,但是我自己用起來還是有很多不足的地方,好在我請(qǐng)教了一些大佬們幫我解決這些問題,在這里也是很感謝他們?。?!接下來話不多說我們直接上代碼?。。?/p>

成果展示

初始化界面:

功能一:添加客戶

我們來看看添加后的效果:

可以看見我們是添加成果了,我們可以繼續(xù)下面的操作。

功能二:修改客戶

我們來看看是否修改成功:

可以看到我們是修改成功的!?。?/p>

功能三:客戶刪除

從圖上看我們是刪除成功的

功能四:展示客戶列表

因?yàn)閯偛虐氧忯~辣椒刪了所以現(xiàn)在只剩鐵甲小寶了哈哈哈哈哈哈哈哈哈哈。

思路分析

我們可以把這個(gè)項(xiàng)目分為三個(gè)部分:

1.數(shù)據(jù)的存儲(chǔ)部分。

2.一些功能函數(shù)部分。

3.可視化界面部分。

1.

首先我們來看看數(shù)據(jù)的存儲(chǔ)是怎么構(gòu)建的:

我們先創(chuàng)建一個(gè)Customer的一個(gè)Java文件,用來存儲(chǔ)數(shù)據(jù),使用構(gòu)造器初始化數(shù)據(jù),并且用private進(jìn)行封裝一些數(shù)據(jù)。并且用 set 和 get 獲取數(shù)據(jù)。

2.

四個(gè)功能函數(shù)的實(shí)現(xiàn)

第一個(gè)就是添加客戶數(shù)據(jù),我們看下面的代碼實(shí)現(xiàn)!!

    public boolean addcust(Customer customer){
        if (total >= customers.length){return false;
        }else{
            customers[total++] = customer;
        }
        return true;
 
    }

第二個(gè)修改:

    public  boolean replacecust(int index , Customer customer){
        if (index<0 || index >= customers.length){
            return false;
        }else{
            customers[index] = customer;
        }
        return true;
    }

第三個(gè)刪除:

    public boolean deletecust(int index){
        if (index<0 || index >= customers.length){
            return false;
        }
       for(int i = index; i< total - 1;i++){
           customers[i] = customers[i+1];
       }
       customers[total-1 ]= null;
       total --;
 
        return true;
 
    }

第四個(gè)查看所有的客戶:

   public  Customer[] getCustomers(){
        Customer[] cus = new Customer[total];
        for(int i = 0; i < total; i++){
            cus[i] = customers[i];
 
        }
        return cus;

嘿嘿嘿,我就偷個(gè)懶,思路我就不具體寫了,大家可以看代碼嘿嘿嘿!

3.

也就是我們?cè)谏厦婵匆姷目梢暬牟糠?,所以我們來?gòu)建這部分:

先創(chuàng)建能讓我們看見的部分:

我們?cè)谑褂霉δ艿臅r(shí)候也是用的數(shù)字選擇,我們可以使用switch結(jié)構(gòu)進(jìn)行選擇,并且在相應(yīng)的數(shù)字里面調(diào)用相對(duì)應(yīng)的函數(shù):

代碼部分

1.數(shù)據(jù)存儲(chǔ)部分:

package cus;
 
public class Customer {
    private String name;
    private char grade;
    private  int age;
    private String phone;
    private String email;
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getName() {
        return name;
    }
 
    public void setAge(int age) {
        this.age = age;
    }
 
    public int getAge() {
        return age;
    }
 
    public void setGrade(char grade) {
        this.grade = grade;
    }
 
    public char getGrade() {
        return grade;
    }
 
    public void setEmail(String email) {
        this.email = email;
    }
 
    public String getEmail() {
        return email;
    }
 
    public void setPhone(String phone) {
        this.phone = phone;
    }
 
    public String getPhone() {
        return phone;
    }
 
    public Customer(){
 
    }
    public Customer(String name ,int age , char grade, String email,String phone ){
        this.name = name;
        this.email = email;
        this.grade = grade;
        this.age = age;
        this.phone = phone;
 
 
    }
}

2.函數(shù)功能部分:

package cus;
 
public class CustomerList {
    private Customer[] customers;
    private static int total = 0;
 
    public CustomerList(int totalCustomerList){
        customers = new Customer[totalCustomerList];
    }
 
 
    public boolean addcust(Customer customer){
        if (total >= customers.length){return false;
        }else{
            customers[total++] = customer;
        }
        return true;
 
    }
    public  boolean replacecust(int index , Customer customer){
        if (index<0 || index >= customers.length){
            return false;
        }else{
            customers[index] = customer;
        }
        return true;
    }
    public boolean deletecust(int index){
        if (index<0 || index >= customers.length){
            return false;
        }
       for(int i = index; i< total - 1;i++){
           customers[i] = customers[i+1];
       }
       customers[total-1 ]= null;
       total --;
 
        return true;
 
    }
    public  Customer[] getCustomers(){
        Customer[] cus = new Customer[total];
        for(int i = 0; i < total; i++){
            cus[i] = customers[i];
 
        }
        return cus;
 
    }
    public Customer getCust(int indsx){
        if(indsx<0 || indsx >= total){
            return null;
        }
        return customers[indsx];    }
    public   int getTotal(){
        return total;
    }
 
}

3.可視化界面部分:

package cus;
import java.util.Scanner;
 
public class View {
    private static CustomerList customerList = new CustomerList(10);
    public View(){
        Customer customer = new Customer("李華",18,'8',"2222@qq.com","123445697");
        customerList.addcust(customer);
    }
    public void enterMain(){
        System.out.println("1.添加用戶");
        System.out.println("2.修改客戶");
        System.out.println("3.刪除客戶");
        System.out.println("4.客戶列表");
        System.out.println("5.退出");
    }
 
 
    public static void main(String[] args) {
        View view = new View();
 
        Scanner scanner = new Scanner(System.in);
        boolean ifFage = true;
        while (ifFage){
            view.enterMain();
            System.out.println("請(qǐng)輸入:");
            switch (scanner.nextInt()){
                case 1:
                    addNewcust();
                    break;
 
                case 2:
                    modifyCust();
                    break;
 
                case 3:
                    System.out.println("請(qǐng)輸入序號(hào):");
                    deleetCust();
                    break;
 
                case 4:
                    listAllCustomer();
                    break;
 
                case 5:
                    System.out.println("是否退出?(1:退出,2:繼續(xù)!?。?);
                    if (scanner.nextInt() == 1){
                    System.out.println("退出!");
                    ifFage = false;}
 
 
            }
 
        }
    }
    private static void  addNewcust(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("姓名:");
        String name = scanner.nextLine();
        System.out.println("年齡:");
        int age = scanner.nextInt();
        System.out.println("性別:");
        char grade = (char)scanner.nextInt();
        System.out.println("郵箱:");
        String email = scanner.next();
        System.out.println("電話:");
        String phone = scanner.next();
 
        Customer customer = new Customer(name,age,grade,email,phone);
        customerList.addcust(customer);
        System.out.println("添加成功!");
 
//        System.out.println("方法1");
 
    }
    private static void modifyCust(){
        Scanner scanner = new Scanner(System.in);
        Customer cust = null ;
        int t;
        for (;;) {
            System.out.println("輸入-1退出!");
            t = scanner.nextInt();
            if (t == -1 ) break;
            cust = customerList.getCust(t-1);
            if(cust == null){
                System.out.println("沒有該用戶!");
            }else{
                break;
            }
        }
        System.out.println("姓名("+cust.getName()+")");
        System.out.println("修改為:");
        String name = scanner.next();
        System.out.println("年齡("+cust.getAge()+")");
        System.out.println("修改為:");
        int age = scanner.nextInt();
        System.out.println("性別("+cust.getGrade()+")");
        System.out.println("修改為:");
        char grade = (char)scanner.nextInt();
        System.out.println("郵箱("+cust.getEmail()+")");
        System.out.println("修改為:");
        String email = scanner.next();
        System.out.println("手機(jī)("+cust.getPhone()+")");
        System.out.println("修改為:");
        String phone = scanner.next();
        Customer customer = new Customer(name,age,grade,email,phone);
        boolean i = customerList.replacecust(t-1,customer);
        if (i == false ){
            System.out.println("修改失??!");
        }else{
            System.out.println("修改成功!");
        }
 
    }
    private static void deleetCust(){
        int total = customerList.getTotal();
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        if(a <0 || a>total)
        {System.out.println("沒有該用戶!");}else{
        boolean customer1 = customerList.deletecust(a-1);
        if (customer1 == false){
            System.out.println("刪除失??!");
        }else {
            System.out.println("刪除成功??!");
        }
        }
    }
    private static void listAllCustomer(){
        int total = customerList.getTotal();
        if (total == 0){
            System.out.println("沒有客戶記錄!");
        }else{
            System.out.println("客戶名單:");
            Customer[] custs = customerList.getCustomers();
            for(int i = 0; i<custs.length ; i++) {
                Customer cust = custs[i];
                System.out.println(i+1+"\t"+cust.getName()+"\t"+cust.getAge()+"\t"+cust.getEmail()+"\t"+cust.getPhone()+"\t"+cust.getGrade());
            }
        }
    }
 
 
}

項(xiàng)目總結(jié)

最后也來說說這個(gè)項(xiàng)目吧,因?yàn)槭蔷毷值男№?xiàng)目,也是我的第一個(gè)Java小項(xiàng)目,所以寫一篇博客記錄一下,并不是什么高級(jí)項(xiàng)目,如果一些大佬覺得寫的垃圾,也可以給我說一下,我會(huì)更加努力的改進(jìn),總得來說任重而道遠(yuǎn)!??!

到此這篇關(guān)于新手易懂的Java客戶管理小項(xiàng)目的文章就介紹到這了,更多相關(guān)Java 客戶管理內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java中使用@CrossOrigin和Proxy解決跨域問題詳解

    Java中使用@CrossOrigin和Proxy解決跨域問題詳解

    這篇文章主要介紹了Java中使用@CrossOrigin和Proxy解決跨域問題詳解,在Web開發(fā)中,如果前端頁面和后端接口不在同一個(gè)域名下,就會(huì)發(fā)生跨域請(qǐng)求的問題,同源策略是瀏覽器的一種安全策略,它限制了來自不同源的客戶端腳本在瀏覽器中運(yùn)行時(shí)的交互,需要的朋友可以參考下
    2023-12-12
  • 如何實(shí)現(xiàn)java遞歸 處理權(quán)限管理菜單樹或分類

    如何實(shí)現(xiàn)java遞歸 處理權(quán)限管理菜單樹或分類

    這篇文章主要介紹了如何實(shí)現(xiàn)java遞歸 處理權(quán)限管理菜單樹或分類,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • 詳解Java中LinkedStack鏈棧的實(shí)現(xiàn)

    詳解Java中LinkedStack鏈棧的實(shí)現(xiàn)

    這篇文章主要為大家詳細(xì)介紹了Java中LinkedStack鏈棧的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Java有一定幫助,需要的可以參考一下
    2022-11-11
  • maven多模塊打包注意事項(xiàng)詳解

    maven多模塊打包注意事項(xiàng)詳解

    這篇文章主要為大家介紹了maven多模塊打包注意事項(xiàng)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • java中文轉(zhuǎn)拼音工具類詳解

    java中文轉(zhuǎn)拼音工具類詳解

    這篇文章主要為大家詳細(xì)介紹了java中文轉(zhuǎn)拼音工具類的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-04-04
  • 基于Spring Boot DevTools實(shí)現(xiàn)開發(fā)過程優(yōu)化

    基于Spring Boot DevTools實(shí)現(xiàn)開發(fā)過程優(yōu)化

    這篇文章主要介紹了基于Spring Boot DevTools實(shí)現(xiàn)開發(fā)過程優(yōu)化,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Java?Zookeeper分布式分片算法超詳細(xì)講解流程

    Java?Zookeeper分布式分片算法超詳細(xì)講解流程

    ZooKeeper是一個(gè)分布式的,開放源碼的分布式應(yīng)用程序協(xié)調(diào)服務(wù),是Google的Chubby一個(gè)開源的實(shí)現(xiàn),是Hadoop和Hbase的重要組件。它是一個(gè)為分布式應(yīng)用提供一致性的軟件,提供的功能包括:配置維護(hù)、域名服務(wù)、分布式同步、組服務(wù)等
    2023-03-03
  • JDK源碼中一些實(shí)用的“小技巧”總結(jié)

    JDK源碼中一些實(shí)用的“小技巧”總結(jié)

    這篇文章主要給大家總結(jié)介紹了關(guān)于JDK源碼中一些實(shí)用的“小技巧”,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用jdk源碼具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • Java編程基本概念

    Java編程基本概念

    本文主要介紹了Java編程的基本概念,具有很好的參考價(jià)值。下面跟著小編一起來看下吧
    2017-03-03
  • Kafka單機(jī)多broker實(shí)例集群搭建教程詳解

    Kafka單機(jī)多broker實(shí)例集群搭建教程詳解

    Apache?Kafka?是一個(gè)分布式流處理平臺(tái),廣泛應(yīng)用于日志收集、監(jiān)控?cái)?shù)據(jù)聚合等,本文將詳細(xì)介紹如何在一個(gè)單機(jī)上搭建多個(gè)Kafka?Broker實(shí)例的步驟,希望對(duì)大家有所幫助
    2025-03-03

最新評(píng)論

海丰县| 香河县| 伽师县| 内乡县| 寻乌县| 翼城县| 安塞县| 邓州市| 青铜峡市| 孝昌县| 桃园县| 浙江省| 博乐市| 苍南县| 大新县| 大厂| 永济市| 长丰县| 公安县| 得荣县| 拜城县| 盐池县| 阜新| 玛沁县| 皮山县| 新竹县| 隆安县| 武陟县| 邓州市| 青阳县| 台中市| 兴海县| 靖边县| 元谋县| 如东县| 武安市| 古浪县| 荥阳市| 特克斯县| 贵德县| 安陆市|