자바 를 이용 하여 고객 정보 관리 시스템 을 실현 하 다.

블 로그 로 제 가 독학 한 것 을 기록 하 겠 습 니 다.
아 날로 그:

Customer 클래스:

public class Customer {
    /**
     * @name     
     * @sex   
     * @age   
     * @phone     
     * @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 클래스:

public class CustomerList {
        private Customer [] customers;
        private static int total = 0;
    /**
     *           
     * @param totalCustmoers      
     */
    public CustomerList(int totalCustmoers){
        customers = new Customer[totalCustmoers];
    }

    /**
     *     
     * @param customer   
     * @return         
     */
        public boolean addCustomer(Customer customer){
            if(customer!=null&&total<customers.length)
            {customers[total]=customer;
                total++;
              return true;}
            else
            { return false;}
        }

    /**
     *  
     * @param index         
     * @param cust      
     * @return         
     */
        public boolean replaceCustomer(int index,Customer cust){
            if(index>=0 && index <total )
            {
                customers[index]=cust;return true;
            }
            else
            {
                return false;
            }
        }

    /**
     *    
     * @param index         
     * @return         
     */
    public boolean deleteCustomer(int index){
        if(index<customers.length)
        {
            for(int i=index;i<total-1;i++)
            {
                customers[i]=customers[i+1];/**       */
            }
                customers[total-1]=null;
                total--;/**        -1*/
             return true;
        }
        else
        {
            return false;
        }
    }

    /**
     *        
     * @param index
     * @return     
     */
    public Customer getCustomer(int index){
        if(index>=0 && index<total)
        {return customers[index];}
        else {
            return null;
        }
    }

    /**
     *        
     * @return   
     */
    public Customer[] getAllCustomers(){
            Customer [] cust = new Customer[total];/**               */
            for(int i=0;i<total;i++){
                cust[i]=customers[i];
            }
            return cust;
    }

    /**
     *        
     * @return
     */
    public int getTotal(){
        return total;
    }
}
CustomerVIEW 클래스:

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

    /**
     *      
     */
    public void enterMainMenu(){

        while(true)
        {System.out.println("-------------------        -------------------");
            System.out.println("1   "+"    ");
            System.out.println("2   "+"    ");
            System.out.println("3   "+"    ");
            System.out.println("4   "+"    ");
            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;
            }
        }
    }


    /**
     *     
     */
    private void addNewCustomer(){
        /**
         *           
         */
        System.out.println("-------------------    -------------------");
        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("    :");
        String phone = input.next();
        System.out.println("    :");
        String email = input.next();
        /**
         *          
         */
        Customer person = new Customer(name,sex,age,phone,email);
        Boolean flag=customerList.addCustomer(person);
        if(flag)
        {
            System.out.println("-------------------    -------------------");
        }
        else
        {
            System.out.println("-------------------    -------------------");
        }
    }

    /**
     *       
     */
    private void modifyCustomer(){
        System.out.println("-------------------    -------------------");
        System.out.println("      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("  (" + customer.getPhone() + "):");
        String phone = CMUtility.readString(13, customer.getPhone());
        System.out.print("  (" + customer.getEmail() + "):");
        String email = CMUtility.readString(15, customer.getEmail());
        /**        */
        customer = new Customer(name,sex,age,phone,email);
        Boolean flag = customerList.replaceCustomer(number,customer);
        if(flag)
        {
            System.out.println("-------------------    -------------------");
        }
        else
        {
            System.out.println("-------------------    -------------------");
        }
    }

    /**
     *     
     */
    private void deleteCustomer(){
        System.out.println("-------------------    -------------------");
        System.out.println("      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("      ");
        }
        else if(number==-1)
        {
            return;
        }
        else
        {
            System.out.println("    ");break;
        }}
        System.out.println("         ?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;
    }
}
/**
 *       
 */
private void listAllCustomers(){
    Customer [] customer=customerList.getAllCustomers();
    if(customer.length==0)
    {
        System.out.println("        ");
    }
    else{
    for(int i=0;i< customer.length;i++)
    {
        System.out.println("  :"+customer[i].getName()+"\t"+"  "+customer[i].getSex()+"\t"+"  :"+customer[i].getAge()+"\t"+"    :"+customer[i].getPhone()+"\t"+"    :"+customer[i].getEmail()+"\t");
    }
}}

    public static void main(String[] args) {
        CustomerView co = new CustomerView();
        co.enterMainMenu();
    }
}
도구 종류:

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("      ,     :");
                }
            }
            return n;
        }
총결산
자 바 를 이용 하여 고객 정보 관리 시스템 을 실현 하 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.자바 고객 정보 관리 시스템 에 관 한 더 많은 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 바 랍 니 다!

좋은 웹페이지 즐겨찾기