客户信息管理软件
作者:互联网
代码包含四个类:BankUtility类用于控制键盘输入输出的准确性,Customer类封装客户个人信息,CustomerList类对客户信息进行增删改查的操作,CustomerView类为主类显示界面和菜单。
用户类:
package newbank;
public class Customer {
private String name;
private String sex;
private String phonenumber;
private String email;
Customer(){
}
Customer(String name,String sex,String phonenumber,String email){
this.name = name;
this.sex = sex;
this.phonenumber = phonenumber;
this.email = email;
}
public void setName(String name) {
if(name != "")
this.name = name;
}
public String getName() {
return name;
}
public void setSex(String sex) {
if(sex != "")
this.sex = sex;
}
public String getSex() {
return sex;
}
public void setPhoneNumber(String phonenumber) {
if(phonenumber != "")
this.phonenumber = phonenumber;
}
public String getPhoneNumber() {
return phonenumber;
}
public void setEmail(String email) {
if(email != "")
this.email = email;
}
public String getEmail() {
return email;
}
}
主界面:
package newbank;
import java.util.Scanner;
public class CustomerView {
public static void main(String[] args) {
int choice;
CustomerList a = new CustomerList();
boolean isflag = true;
while(isflag) {
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.print(" 请选择(1-4): ");
choice = BankUtility.readChoice();
System.out.println();
switch (choice) {
case '1' :
a.addNewCustomer();
break;
case '2' :
a.changeCustomer();
break;
case '3' :
a.deleteCustomer();
break;
case '4' :
a.showCustomer();
break;
case '5' :
System.out.print("你确定要退出吗(Y/N): ");
char isExit = BankUtility.readSeletion();
if(isExit == 'Y')
isflag = false;
}
}
}
}
运行效果:
各方法的实现:
1. 添加客户
public void addNewCustomer() {
customer[customernumber] = new Customer();
System.out.println("---------------添加客户----------------");
System.out.print("姓名: ");
customer[customernumber].setName(BankUtility.readName());
System.out.println();
System.out.print("性别: ");
customer[customernumber].setSex(BankUtility.readSex());
System.out.println();
System.out.print("电话号码: ");
customer[customernumber].setPhoneNumber(BankUtility.readPhoneNumber());
System.out.println();
System.out.print("邮箱: ");
customer[customernumber].setEmail(BankUtility.readEmail());
System.out.println();
System.out.println("---------------添加完成----------------");
System.out.println();
customernumber++;
}
2.修改用户信息
public void changeCustomer() {
System.out.println("---------------修改客户----------------");
System.out.print("请选择要修改的客户编号(输入-1退出): ");
int number = BankUtility.readCustomerNumber();
while(number != -1){
if(number > 0 && number <= customernumber - 1) {
System.out.print("(姓名)" + customer[number].getName() +": ");
customer[number].setName(BankUtility.readName());
System.out.println();
System.out.print("(性别)" + customer[number].getSex() + ": ");
customer[number].setSex(BankUtility.readSex());
System.out.println();
System.out.print("(电话号码)" + customer[number].getPhoneNumber() + ": ");
customer[number].setPhoneNumber(BankUtility.readPhoneNumber());
System.out.println();
System.out.print("(邮箱)" + customer[number].getEmail() + ": ");
customer[number].setEmail(BankUtility.readEmail());
break;
}
else {
System.out.println("无法找到指定用户!");
System.out.print("请重新输入:");
number = BankUtility.readCustomerNumber();
}
};
System.out.println("---------------修改完成----------------");
System.out.println();
}
3.删除用户
public void deleteCustomer() {
System.out.println("---------------删除客户----------------");
System.out.print("请选择你要删除的用户(输入-1退出): ");
int number = BankUtility.readCustomerNumber();
while(number != -1){
if(number > 0 && number <= customernumber - 1) {
System.out.print("你确定要删除用户吗(Y/N): ");
char c = BankUtility.readSeletion();
if(c == 'Y') {
for(int i = number;i < customernumber;i++) {
customer[i] = customer[i+1];
}
customernumber--;
System.out.println("---------------删除成功----------------");
}
break;
}
else {
System.out.println("无法找到指定用户!");
System.out.print("请选择你要删除的用户(输入-1退出): ");
number = BankUtility.readCustomerNumber();
}
};
System.out.println();
}
4.显示所有用户
public void showCustomer() {
System.out.println("---------------客户列表----------------");
System.out.println();
System.out.println("编号\t\t姓名\t\t性别\t\t电话号码\t\t邮箱");
for(int i = 1;i < customernumber;i++) {
System.out.println(i + "\t\t" + customer[i].getName() + "\t\t" + customer[i].getSex() + "\t\t" + customer[i].getPhoneNumber() + "\t" + customer[i].getEmail());
}
System.out.println();
}
标签:String,信息管理,System,客户,phonenumber,println,软件,public,out 来源: https://blog.csdn.net/qq_58235516/article/details/120579297