00010.02最基础客户信息管理软件(意义类的小项目,练习基础,不涉及数据库)
发布日期:2021-05-15 23:23:27 浏览次数:7 分类:精选文章

本文共 4952 字,大约阅读时间需要 16 分钟。

���������������������������

������������������������������������Java������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������

������������������������������������������������

1. ������������Bean���

  • ������������������������������������������������������������������������
package com.atguigu.bean;public class Customer {    private String name;    private char gender;    private int age;    private String phone;    private String email;    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;    }    //getter���setter������}

2. ������������������Service���

  • ������������������������������������������������������������������������������������
package com.atguigu.service;import com.atguigu.bean.Customer;public class CustomerService {    private Customer[] all;    private int total;    public CustomerService() {        all = new Customer[2];    }    public void addCustomer(Customer customer) {        if (total >= all.length) {            System.out.println("������������");            return;        }        all[total++] = customer;    }}

3. ������������View���

  • ������������������������������������������������������������������������������������
package com.atguigu.view;import com.atguigu.bean.Customer;import com.atguigu.utils.CMUtility;import com.atguigu.service.CustomerService;public class CustomerView {    private CustomerService service = new CustomerService();    public void menu() {        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("������������������1-5������");        char choice = CMUtility.readMenuSelection();        switch (choice) {            case '1': addCustomer(); break;            case '2': editCustomer(); break;            case '3': deleteCustomer(); break;            case '4': listCustomers(); break;            case '5': logout(); break;        }    }}

������������������

1. ������������

public void addCustomer() {    System.out.println("-------������������---------");    System.out.print("��������� ");    String name = CMUtility.readString(20);    System.out.print("��������� ");    char gender = CMUtility.readChar();    System.out.print("��������� ");    int age = CMUtility.readInt();    System.out.print("��������� ");    String phone = CMUtility.readString(11);    System.out.print("��������� ");    String email = CMUtility.readString(32);    Customer customer = new Customer(name, gender, age, phone, email);    service.addCustomer(customer);    System.out.println("-------------������������-------------");    menu();}

2. ������������

public void deleteCustomer() {    System.out.println("-------------������������-----------------------");    System.out.println("������������������������������������-1������������ ");    int id = CMUtility.readInt();    if (id == -1) {        return;    }    System.out.print("���������������Y/N������ ");    char confirm = CMUtility.read ConfirmSelection();    if (confirm != 'Y') {        menu();        return;    }    service.removeById(id);    System.out.println("-------------������������-----------------------");    menu();}

3. ������������������

public void listCustomers() {    System.out.println("--------������������--------------");    System.out.println("������  ������  ������  ������  ������  ������");    Customer[] customers = service.getAll();    for (int i = 0; i < customers.length; i++) {        System.out.println((i + 1) + "\t" + customers[i].getInfo());    }    System.out.println();    System.out.println("-------------������������������-----------------------");    menu();}

���������������

1. ������������

  • ���������IntelliJ IDEA
  • ���������
  • ������������������������������������������
  • ������������������������Debugger������������������
  • ������������������������������������������

2. ���������

package com.atguigu.test;import com.atguigu.view.CustomerView;public class Test {    public static void main(String[] args) {        CustomerView view = new CustomerView();        view.menu();    }}

������������������

  • ������������������������
  • ������������������������������������
  • ���������������������������������������
  • ���������������������������������������
  • ���������������������������������
  • ������

    ���������������������������������������������������������������������������������������������Java������������������������������������������������������������������������������������������������������������������

    上一篇:00011.0关键字final
    下一篇:00010.01eclipse建立工作集

    发表评论

    最新留言

    关注你微信了!
    [***.104.42.241]2025年04月08日 00时19分07秒