用java编写一个客户信息管理系统,包括个人客户和企业客户,用showInfo显示客户信息,用add添加客户信息用PrintCustomer输出客户信息
时间: 2024-02-16 13:01:37 浏览: 26
好的,我可以帮您回答这个问题。
首先,我们需要定义客户类(Customer),包括个人客户(PersonalCustomer)和企业客户(EnterpriseCustomer)两个子类。客户类需要包括以下属性:
- 客户编号(id)
- 客户姓名(name)
- 客户性别(gender)
- 客户电话(telephone)
- 客户地址(address)
我们可以使用以下Java代码来定义客户类:
```
public abstract class Customer {
private String id;
private String name;
private String gender;
private String telephone;
private String address;
public Customer(String id, String name, String gender, String telephone, String address) {
this.id = id;
this.name = name;
this.gender = gender;
this.telephone = telephone;
this.address = address;
}
public abstract void showInfo();
}
```
```
public class PersonalCustomer extends Customer {
private String birthday;
public PersonalCustomer(String id, String name, String gender, String telephone, String address, String birthday) {
super(id, name, gender, telephone, address);
this.birthday = birthday;
}
@Override
public void showInfo() {
System.out.println("个人客户信息:");
System.out.println("客户编号:" + super.id);
System.out.println("客户姓名:" + super.name);
System.out.println("客户性别:" + super.gender);
System.out.println("客户电话:" + super.telephone);
System.out.println("客户地址:" + super.address);
System.out.println("客户生日:" + birthday);
}
}
```
```
public class EnterpriseCustomer extends Customer {
private String enterpriseName;
public EnterpriseCustomer(String id, String name, String gender, String telephone, String address, String enterpriseName) {
super(id, name, gender, telephone, address);
this.enterpriseName = enterpriseName;
}
@Override
public void showInfo() {
System.out.println("企业客户信息:");
System.out.println("客户编号:" + super.id);
System.out.println("客户姓名:" + super.name);
System.out.println("客户性别:" + super.gender);
System.out.println("客户电话:" + super.telephone);
System.out.println("客户地址:" + super.address);
System.out.println("企业名称:" + enterpriseName);
}
}
```
接下来,我们需要定义一个客户管理类(CustomerManager),用于添加客户信息和输出客户信息。客户管理类需要包括以下方法:
- add():添加客户信息
- showInfo():输出客户信息
我们可以使用以下Java代码来定义客户管理类:
```
import java.util.ArrayList;
import java.util.List;
public class CustomerManager {
private List<Customer> customers;
public CustomerManager() {
customers = new ArrayList<>();
}
public void add(Customer customer) {
customers.add(customer);
}
public void showInfo() {
for (Customer customer : customers) {
customer.showInfo();
}
}
}
```
最后,我们可以使用以下Java代码来测试客户信息管理系统:
```
public class Main {
public static void main(String[] args) {
CustomerManager customerManager = new CustomerManager();
PersonalCustomer personalCustomer = new PersonalCustomer("001", "张三", "男", "13812345678", "北京市海淀区", "1990-01-01");
customerManager.add(personalCustomer);
EnterpriseCustomer enterpriseCustomer = new EnterpriseCustomer("002", "ABC公司", "女", "13912345678", "北京市朝阳区", "ABC公司");
customerManager.add(enterpriseCustomer);
customerManager.showInfo();
}
}
```
输出结果为:
```
个人客户信息:
客户编号:001
客户姓名:张三
客户性别:男
客户电话:13812345678
客户地址:北京市海淀区
客户生日:1990-01-01
企业客户信息:
客户编号:002
客户姓名:ABC公司
客户性别:女
客户电话:13912345678
客户地址:北京市朝阳区
企业名称:ABC公司
```
这样就完成了一个简单的客户信息管理系统。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)