当前位置:网站首页>Customer information management software
Customer information management software
2022-06-11 21:29:00 【Yzhenfeng7】
This project uses java Basic , After output, the following functions of adding, deleting, modifying and querying can be realized

First
A new project is called myProject, And then in src Create folder inside net.seehope As the home folder , Then create four small folders in turn bean,service,ui,util ;
bean It creates Customer class , service It creates CustomerList class ,
ui It creates CustomerView class ,util It creates CMUtility class

then
Let's write these four classes separately
The first is util In a folder CMUtility Tool class , This is actually a tool kit , When calling this class , You can enter the corresponding type .
package net.seehope.util;
import java.util.Scanner;
public class CMUtility {
// Encapsulating different functions into methods , You can use its functions by calling methods , There is no need to consider the specific function implementation details .
private static Scanner scanner = new Scanner(System.in);
// The following method is used to select the interface menu . This method reads the keyboard , If the user types ’1’-’5’ Any character in , Then the method returns . The return value is the character that the user typed .
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(" Wrong choice , Please re-enter :");
} else break;
}
return c;
}
// Read a character from the keyboard , And take it as the return value of the method .
public static char readChar() {
String str = readKeyBoard(1, false);
return str.charAt(0);
}
// Read a character from the keyboard , And take it as the return value of the method .
// If the user does not enter a character and returns directly , Method will defaultValue As return value .
public static char readChar(char defaultValue) {
String str = readKeyBoard(1, true);
return (str.length() == 0) ? defaultValue : str.charAt(0);
}
// Read from the keyboard a length not more than 2 An integer , And take it as the return value of the method .
public static int readInt() {
int n;
for (; ; ) {
String str = readKeyBoard(2, false);
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print(" Wrong number input , Please re-enter :");
}
}
return n;
}
// Read from the keyboard a length not more than 2 An integer , And take it as the return value of the method .
// If the user does not enter a character and returns directly , Method will defaultValue As return value .
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(" Wrong number input , Please re-enter :");
}
}
return n;
}
// Read from the keyboard a length not more than limit String , And take it as the return value of the method .
public static String readString(int limit) {
return readKeyBoard(limit, false);
}
// Read from the keyboard a length not more than limit String , And take it as the return value of the method .
// If the user does not enter a character and returns directly , Method will defaultValue As return value .
public static String readString(int limit, String defaultValue) {
String str = readKeyBoard(limit, true);
return str.equals("")? defaultValue : str;
}
// Input to confirm selection . This method reads... From the keyboard ‘Y’ or ’N’, And take it as the return value of the method .
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(" Wrong choice , Please re-enter :");
}
}
return c;
}
// Read the value in the keyboard
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(" Input length ( No more than " + limit + ") error , Please re-enter :");
continue;
}
break;
}
return line;
}
}
next
Write Customer class , Create private variables name gender age phone email, Then Jianli get set Method And constructing nonparametric and parametric methods
package net.seehope.bean;
public class Customer {
private String name;
private char gender;
private int age;
private String phone;
private String 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;
}
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;
}
}
Until then
CustomerList class , Is used to save the customer object array , And the method of constructing addition, deletion, modification and query is in it .
package net.seehope.service;
import net.seehope.bean.Customer;
public class CustomerList {
private Customer[] customers;// An array to hold the customer object
private int total;// Record the number of saved customer objects
/**
* Used to initialize customers The constructor of an array
* @param totalCustomer: Specify the length of the array
*/
public CustomerList(int totalCustomer) {
customers = new Customer[totalCustomer];
}
/**
*
* @Description Add the specified customer to the array
* @author shkstart
* @date 2021 year 1 month 19 The morning of 11:14:51
* @param customer
* @return true: Add success false: Add failure
*/
public boolean addCustomer(Customer customer) {
if(total >=customers.length){
return false;
}else{
customers[total++] = customer;
return true;
}
}
/**
*
* @Description Modify customer information at the specified index location
* @author shkstart
* @date 2021 year 1 month 19 The morning of 11:17:28
* @param index
* @param cust
* @return true: Modification successful false: Modification failed
*/
public boolean replaceCustomer(int index,Customer cust){
if(index < 0 || index >=total){
return false;
}else{
customers[index] = cust;
return true;
}
}
/**
* Delete the customer at the specified index location
* @Description
* @author shkstart
* @date 2021 year 1 month 19 The morning of 11:23:03
* @param index
* @return true: Delete successful false: Delete failed
*/
public boolean deleteCustomer(int index){
if(index < 0 || index >=total){
return false;
}else{
for(int i =index;i<total - 1;i++){
customers[i] = customers[i+1];
}
// customers[total - 1] = null;
// total--;
// or
customers[--total] = null;
return true;
}
}
/**
*
* @Description Get all the customer information
* @author shkstart
* @date 2021 year 1 month 19 The morning of 11:28:53
* @return
*/
public Customer[] getAllCustomers(){
Customer[] custs = new Customer[total];
for(int i = 0;i < total;i++){
custs[i] = customers[i];
}
return custs;
}
/**
*
* @Description Gets the customer at the specified index location
* @author shkstart
* @date 2021 year 1 month 19 The morning of 11:31:45
* @param index
* @return If you find the elements , Then return to ; If not found , Then return to null
*/
public Customer getCustomer(int index) {
if(index < 0 || index >= total){
return null;
}else{
return customers[index];
}
}
/**
*
* @Description Get the number of customers stored
* @author shkstart
* @date 2021 year 1 month 19 The morning of 11:32:52
* @return
*/
public int getTotal(){
return total;
// return customers.length;// FALSE
}
}
Last
We wrote CustomerView Class is the first picture shown at the beginning , It's written inside Menu items and items 1-5 Demonstration of methods , Finally, add one more main Method first calls the menu item
package net.seehope.ui;
import net.seehope.bean.Customer;
import net.seehope.service.CustomerList;
import net.seehope.util.CMUtility;
public class CustomerView {
private CustomerList customerList = new CustomerList(10);
public CustomerView() {
Customer customer = new Customer(" Wang Tao ", ' male ', 23, "13212341234", "[email protected]");
customerList.addCustomer(customer);
}
/**
* Show 《 Customer information management software 》 Interface method
*
* @Description
* @author shkstart
* @date 2021 year 1 month 19 The morning of 11:36:26
*/
public void enterMainMenu() {
boolean isFlag = true;
while (isFlag) {
System.out.println("\n----------------- Customer information management software -----------------\n");
System.out.println(" 1 add Add customer Household ");
System.out.println(" 2 repair Change customer Household ");
System.out.println(" 3 Delete except customer Household ");
System.out.println(" 4 customer Household Column surface ");
System.out.println(" 5 refund Out \n");
System.out.print(" Please select (1-5):");
char menu = CMUtility.readMenuSelection();
switch (menu) {
case '1':
addNewCustomer();
break;
case '2':
modifyCustomer();
break;
case '3':
deleteCustomer();
break;
case '4':
listAllCustomer();
break;
case '5':
System.out.print(" Confirm whether to exit (Y/N)");
char isExit = CMUtility.readConfirmSelection();
if (isExit == 'Y') {
isFlag = false;
}
break;
}
}
}
private void listAllCustomer() {
System.out.println("--------------------------- Customer list ---------------------------\n");
int total = customerList.getTotal();
if (total == 0) {
System.out.println(" No customer records ");
} else {
System.out.println(" Number \t full name \t Gender \t Age \t\t Telephone \t\t\t\t mailbox ");
Customer[] custs = customerList.getAllCustomers();
for (int i = 0; i < custs.length; i++) {
Customer cust = custs[i];
System.out.println((i + 1) + "\t" + cust.getName() + "\t" + cust.getGender() + "\t" + cust.getAge() +
"\t" + cust.getPhone() + "\t" + cust.getEmail());
}
System.out.println("------------------------- Customer list complete -------------------------");
}
}
private void deleteCustomer () {
System.out.println("--------------------- Delete customer ---------------------");
int number;
for(;;){
System.out.print(" Please select the customer number to be deleted (-1 sign out ):");
number = CMUtility.readInt();
if(number == -1){
return;
}
Customer customer = customerList.getCustomer(number - 1);
if(customer == null){
System.out.println(" Unable to find the specified customer !");
}else{
break;
}
}
// Found the designated customer
System.out.print(" Confirm whether to delete (Y/N):");
char isDelete = CMUtility.readConfirmSelection();
if(isDelete == 'Y'){
boolean deleteSuccess = customerList.deleteCustomer(number - 1);
if(deleteSuccess){
System.out.println("--------------------- Delete complete ---------------------");
}else{
System.out.println("--------------------- Delete failed ---------------------");
}
}else{
return;
}
}
private void modifyCustomer () {
System.out.println("--------------------- Modify customer ---------------------");
Customer cust;
int number;
for(;;){
System.out.print(" Please select the customer number to be modified (-1 sign out ):");
number = CMUtility.readInt();
if(number == -1){
return;
}
cust = customerList.getCustomer(number - 1);
if(cust == null){
System.out.println(" Unable to find the specified customer ");
}else{
break;
}
}
// Modify customer information
System.out.println(" full name ("+cust.getName()+"):");
String name = CMUtility.readString(10,cust.getName());
System.out.print(" Gender (" + cust.getGender() + "):");
char gender = CMUtility.readChar(cust.getGender());
System.out.print(" Age (" + cust.getAge() + "):");
int age = CMUtility.readInt(cust.getAge());
System.out.print(" Telephone (" + cust.getPhone() + "):");
String phone = CMUtility.readString(13, cust.getPhone());
System.out.print(" mailbox (" + cust.getEmail()+ "):");
String email = CMUtility.readString(30, cust.getEmail());
Customer newCust = new Customer(name, gender, age, phone, email);
boolean isRepalaced = customerList.replaceCustomer(number - 1,newCust);
if(isRepalaced){
System.out.println("--------------------- Modified to complete ---------------------");
}else{
System.out.println("--------------------- Modification failed ---------------------");
}
}
public void addNewCustomer () {
System.out.println("--------------------- Add customers ---------------------");
System.out.print(" full name :");
String name = CMUtility.readString(10);
System.out.print(" Gender :");
char gender = CMUtility.readChar();
System.out.print(" Age :");
int age = CMUtility.readInt();
System.out.print(" Telephone :");
String phone = CMUtility.readString(13);
System.out.print(" mailbox :");
String email = CMUtility.readString(30);
// Encapsulate the above data into objects
Customer customer = new Customer(name,gender,age,phone,email);
boolean isSuccess = customerList.addCustomer(customer);
if(isSuccess) {
System.out.println("--------------------- Add to complete ---------------------");
}else {
System.out.println("------------------- The customer directory is full , Add failure ---------------");
}
}
public static void main (String[]args){
CustomerView view = new CustomerView();
view.enterMainMenu();
}
}
Let's take a look at the display effect :
Add customers :

Modify customer :
there “ Wang Tao ” It is an object established in advance at the beginning of the project , Then when modifying , If enter CMutility The original default value will be kept unchanged .

Delete customer :

Customer list :

sign out :

For the time being , It needs to be optimized and adjusted later .
边栏推荐
- Codeworks round 744 (Div. 3) problem solving Report
- How to create the simplest SAP kyma function
- Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system
- Codeworks round 740 Div. 2 problem solving Report
- apache 本地多端口配置
- 如何创建最简单的 SAP Kyma Function
- A problem of setting the private library of golang
- Bug -- coredump usage
- One article to show you how to understand the harmonyos application on the shelves
- LeetCode-32-最长有效括号
猜你喜欢
![BZOJ3189 : [Coci2011] Slika](/img/46/c3aa54b7b3e7dfba75a7413dfd5b68.png)
BZOJ3189 : [Coci2011] Slika

Deriving Kalman filter from probability theory

Part I physical layer

Answer fans' questions | count the number and frequency of letters in the text

One article to show you how to understand the harmonyos application on the shelves

LeetCode-322-零钱兑换

【C語言進階】整型在內存中的存儲

Network security Kali penetration learning introduction to web penetration using MSF penetration to attack win7 host and execute commands remotely

Leetcode-129- sum of numbers from root node to leaf node

ORA-04098: trigger ‘xxx. xxx‘ is invalid and failed re-validation
随机推荐
ORA-04098: trigger ‘xxx. xxx‘ is invalid and failed re-validation
[Part 13] source code analysis and application details of completabilefuture class [key]
Deriving Kalman filter from probability theory
【生活思考】文字与语音
JS performs non empty judgment on various data types of the returned data.
一步步把 SAP UI5 应用部署到 SAP BTP Kyma 运行环境中去
Go language for loop
LabVIEW controls Arduino to realize infrared ranging (advanced chapter-6)
Hangzhou Electric Zhongchao 91006 guess the weight
Codeforces Round #742 (Div. 2) F. One-Four Overload
Add personal statement for go file in file template in Golan
Leetcode-104- maximum depth of binary tree
Application business layer modification
JVM|虚拟机栈(局部变量表;操作数栈;动态链接;方法的绑定机制;方法的调用;方法返回地址)
Software test plan
LabVIEW controls Arduino to realize ultrasonic ranging (advanced chapter-5)
字符串复制函数
bzoj3188 Upit
线性表的链式存储结构
Analysis on the development history and market development status of China's system integration industry in 2020 [figure]