结合面向对象编程思想,开发“裹裹快投”快递服务控制台程序,可实现用户寄件、取件、查询订单、修改订单、取消订单等功能。 具体要求如下: (1)显示系统主菜单 包括寄件、取件、查询订单、修改订单、取消订单...
时间: 2023-10-20 10:17:50 浏览: 61
好的,我可以为您提供一些面向对象编程思想的建议来实现这个功能。
首先,我们需要定义一个名为 "Order" 的类来存储订单信息,包括订单号、寄件人姓名、寄件人地址、收件人姓名、收件人地址、订单状态等属性。我们还可以为这个类定义一些操作方法,如修改订单状态、获取订单信息等。
接下来,我们可以定义一个名为 "DeliveryService" 的类来管理所有订单,包括添加订单、删除订单、修改订单、查询订单等操作。我们可以将这些操作封装成方法,并在控制台程序中调用这些方法来实现相应的功能。
在程序运行时,我们可以使用一个菜单来显示所有可用的操作,然后通过用户输入来选择要执行的操作。例如:
```
Welcome to Guo Guo Express!
1. Send package
2. Pick up package
3. View order
4. Modify order
5. Cancel order
6. Exit
Please select an option:
```
一旦用户选择了一个选项,程序将会调用相应的方法来执行该操作,并返回相应的结果。
当然,这只是一个基本的框架,您可以根据实际需求来添加更多的功能和细节。
相关问题
结合面向对象编程思想,开发“裹裹快投”快递服务控制台程序,可实现用户寄件、取件、查询订单、修改订单、取消订单等功能
好的,首先我们需要确定一下程序的基本结构和需要用到的对象。根据需求,我们可以考虑以下对象:
1. 用户对象:包含用户的基本信息,如姓名、手机号等。
2. 快递对象:包含快递的基本信息,如快递单号、寄件人信息、收件人信息、快递状态等。
3. 订单对象:包含订单的基本信息,如订单号、寄件人信息、收件人信息、快递信息等。
基于以上对象,我们可以定义以下类:
1. User(用户类):包含用户的基本信息,如姓名、手机号等。可实现用户的信息修改功能。
2. Express(快递类):包含快递的基本信息,如快递单号、寄件人信息、收件人信息、快递状态等。可实现快递状态修改功能。
3. Order(订单类):包含订单的基本信息,如订单号、寄件人信息、收件人信息、快递信息等。可实现订单的查询、修改、取消等功能。
4. Console(控制台类):可实现用户输入指令、调用各种功能实现快递服务的控制台程序。
基于以上类,我们可以实现以下功能:
1. 用户输入指令,控制台程序调用 User 类实现用户信息修改功能。
2. 用户输入指令,控制台程序调用 Express 类实现快递状态修改功能。
3. 用户输入指令,控制台程序调用 Order 类实现订单查询、修改、取消等功能。
具体实现过程如下:
1. User 类:
```python
class User:
def __init__(self, name, phone):
self.name = name
self.phone = phone
def modify_info(self, new_name, new_phone):
self.name = new_name
self.phone = new_phone
```
2. Express 类:
```python
class Express:
def __init__(self, express_id, sender_name, sender_phone, receiver_name, receiver_phone, status):
self.express_id = express_id
self.sender_name = sender_name
self.sender_phone = sender_phone
self.receiver_name = receiver_name
self.receiver_phone = receiver_phone
self.status = status
def modify_status(self, new_status):
self.status = new_status
```
3. Order 类:
```python
class Order:
def __init__(self, order_id, sender_name, sender_phone, receiver_name, receiver_phone, express):
self.order_id = order_id
self.sender_name = sender_name
self.sender_phone = sender_phone
self.receiver_name = receiver_name
self.receiver_phone = receiver_phone
self.express = express
def query_order(self):
# 查询订单信息
pass
def modify_order(self, new_sender_name, new_sender_phone, new_receiver_name, new_receiver_phone, new_express):
# 修改订单信息
pass
def cancel_order(self):
# 取消订单
pass
```
4. Console 类:
```python
class Console:
def __init__(self):
self.users = []
self.expresses = []
self.orders = []
def add_user(self, name, phone):
user = User(name, phone)
self.users.append(user)
def add_express(self, express_id, sender_name, sender_phone, receiver_name, receiver_phone, status):
express = Express(express_id, sender_name, sender_phone, receiver_name, receiver_phone, status)
self.expresses.append(express)
def add_order(self, order_id, sender_name, sender_phone, receiver_name, receiver_phone, express):
order = Order(order_id, sender_name, sender_phone, receiver_name, receiver_phone, express)
self.orders.append(order)
def query_order(self, order_id):
# 根据订单号查询订单信息
pass
def modify_order(self, order_id, new_sender_name, new_sender_phone, new_receiver_name, new_receiver_phone, new_express):
# 根据订单号修改订单信息
pass
def cancel_order(self, order_id):
# 根据订单号取消订单
pass
```
以上是一个基本的“裹裹快投”快递服务控制台程序的设计,具体实现中还需要根据需求进行修改和完善。
Java结合面向对象编程思想,开发“裹裹快投”快递服务控制台程序,可实现用户寄件、取件、查询订单、修改订单、取消订单等功能
好的,下面我会给你提供一些实现思路和代码示例。
首先,我们可以定义一个 `Order` 类来表示快递订单,包含以下属性:
```java
public class Order {
private String orderId; // 订单号
private String senderName; // 寄件人姓名
private String senderPhone; // 寄件人电话
private String senderAddress; // 寄件人地址
private String receiverName; // 收件人姓名
private String receiverPhone; // 收件人电话
private String receiverAddress; // 收件人地址
private double weight; // 快递重量
private double fee; // 快递费用
private String status; // 订单状态:已下单、已发货、已签收、已取消
// 构造方法
public Order(String orderId, String senderName, String senderPhone, String senderAddress,
String receiverName, String receiverPhone, String receiverAddress, double weight) {
this.orderId = orderId;
this.senderName = senderName;
this.senderPhone = senderPhone;
this.senderAddress = senderAddress;
this.receiverName = receiverName;
this.receiverPhone = receiverPhone;
this.receiverAddress = receiverAddress;
this.weight = weight;
this.fee = calculateFee(); // 根据重量计算费用
this.status = "已下单"; // 初始状态为已下单
}
// 计算快递费用
private double calculateFee() {
// 这里可以根据快递公司的计费标准进行计算,这里简化为按每公斤5元计算
return weight * 5;
}
// 修改订单状态
public void setStatus(String status) {
this.status = status;
}
// 取消订单,将状态设置为已取消
public void cancelOrder() {
this.status = "已取消";
}
// 获取订单信息
public String getInfo() {
return "订单号:" + orderId +
"\n寄件人:" + senderName + ",电话:" + senderPhone + ",地址:" + senderAddress +
"\n收件人:" + receiverName + ",电话:" + receiverPhone + ",地址:" + receiverAddress +
"\n重量:" + weight + "kg,费用:" + fee + "元,状态:" + status;
}
}
```
接下来,我们可以定义一个 `ExpressService` 类来管理订单,包含以下方法:
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class ExpressService {
private List<Order> orderList; // 订单列表
private int currentOrderId; // 当前订单号
// 构造方法,初始化订单列表和当前订单号
public ExpressService() {
this.orderList = new ArrayList<>();
this.currentOrderId = 10000; // 初始订单号为10000
}
// 生成新订单号
private String generateOrderId() {
return "GGKT" + currentOrderId++;
}
// 添加订单
public void addOrder() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入寄件人姓名:");
String senderName = scanner.nextLine();
System.out.println("请输入寄件人电话:");
String senderPhone = scanner.nextLine();
System.out.println("请输入寄件人地址:");
String senderAddress = scanner.nextLine();
System.out.println("请输入收件人姓名:");
String receiverName = scanner.nextLine();
System.out.println("请输入收件人电话:");
String receiverPhone = scanner.nextLine();
System.out.println("请输入收件人地址:");
String receiverAddress = scanner.nextLine();
System.out.println("请输入快递重量(kg):");
double weight = scanner.nextDouble();
scanner.nextLine(); // 清空缓冲区
Order order = new Order(generateOrderId(), senderName, senderPhone, senderAddress,
receiverName, receiverPhone, receiverAddress, weight);
orderList.add(order);
System.out.println("订单已创建,订单号为:" + order.getOrderId());
}
// 查询订单
public void queryOrder() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要查询的订单号:");
String orderId = scanner.nextLine();
for (Order order : orderList) {
if (order.getOrderId().equals(orderId)) {
System.out.println(order.getInfo());
return;
}
}
System.out.println("未找到该订单!");
}
// 修改订单
public void modifyOrder() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要修改的订单号:");
String orderId = scanner.nextLine();
for (Order order : orderList) {
if (order.getOrderId().equals(orderId)) {
System.out.println(order.getInfo());
System.out.println("请输入要修改的内容(1-寄件人姓名,2-寄件人电话,3-寄件人地址,4-收件人姓名,5-收件人电话,6-收件人地址,7-快递重量):");
int choice = scanner.nextInt();
scanner.nextLine(); // 清空缓冲区
switch (choice) {
case 1:
System.out.println("请输入新的寄件人姓名:");
String senderName = scanner.nextLine();
order.setSenderName(senderName);
break;
case 2:
System.out.println("请输入新的寄件人电话:");
String senderPhone = scanner.nextLine();
order.setSenderPhone(senderPhone);
break;
case 3:
System.out.println("请输入新的寄件人地址:");
String senderAddress = scanner.nextLine();
order.setSenderAddress(senderAddress);
break;
case 4:
System.out.println("请输入新的收件人姓名:");
String receiverName = scanner.nextLine();
order.setReceiverName(receiverName);
break;
case 5:
System.out.println("请输入新的收件人电话:");
String receiverPhone = scanner.nextLine();
order.setReceiverPhone(receiverPhone);
break;
case 6:
System.out.println("请输入新的收件人地址:");
String receiverAddress = scanner.nextLine();
order.setReceiverAddress(receiverAddress);
break;
case 7:
System.out.println("请输入新的快递重量(kg):");
double weight = scanner.nextDouble();
scanner.nextLine(); // 清空缓冲区
order.setWeight(weight);
order.setFee(order.calculateFee()); // 重新计算费用
break;
default:
System.out.println("输入有误!");
return;
}
System.out.println("订单已修改,新信息为:");
System.out.println(order.getInfo());
return;
}
}
System.out.println("未找到该订单!");
}
// 取消订单
public void cancelOrder() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要取消的订单号:");
String orderId = scanner.nextLine();
for (Order order : orderList) {
if (order.getOrderId().equals(orderId)) {
order.cancelOrder();
System.out.println("订单已取消!");
return;
}
}
System.out.println("未找到该订单!");
}
// 显示所有订单
public void showAllOrders() {
System.out.println("所有订单如下:");
for (Order order : orderList) {
System.out.println(order.getInfo());
System.out.println("--------------------");
}
}
}
```
最后,我们可以定义一个 `Main` 类来实现控制台程序的交互:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ExpressService expressService = new ExpressService();
Scanner scanner = new Scanner(System.in);
boolean flag = true;
while (flag) {
System.out.println("请选择操作(1-寄件,2-查询订单,3-修改订单,4-取消订单,5-显示所有订单,0-退出程序):");
int choice = scanner.nextInt();
scanner.nextLine(); // 清空缓冲区
switch (choice) {
case 1:
expressService.addOrder();
break;
case 2:
expressService.queryOrder();
break;
case 3:
expressService.modifyOrder();
break;
case 4:
expressService.cancelOrder();
break;
case 5:
expressService.showAllOrders();
break;
case 0:
flag = false;
System.out.println("程序已退出!");
break;
default:
System.out.println("输入有误!");
break;
}
}
}
}
```
这样,我们就完成了一个简单的快递服务控制台程序,可以实现用户寄件、取件、查询订单、修改订单、取消订单等功能。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.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_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)