第二次blog作业

第二次blog作业-航空货运管理系统分析

前言

对于题目集8,9的前两道题在此不过多赘述,因为都是对继承与多态的不断学习以及加深印象,代码复杂度以及长度并不高,主要是为了航空货运管理系统服务。

本次航空货运管理相较于电梯代码复杂度更为简单,对于思维逻辑的要求并没有那么高,主要是对学习的抽象类,继承与多态,合成复用等的学习内容进行实践。

航空货运管理系统第一次作业分析

作业要求如下:

一、计费重量的确定

空运以实际重量(Gross Weight)和体积重量(Volume Weight)中的较 高者作为计费重量。 计算公式: 体积重量(kg= 货物体积(长××高,单位:厘米)÷ 6000

示例: 若货物实际重量为 80kg,体积为 120cm×80cm×60cm,则: 体积重量 = (120×80×60) ÷ 6000 = 96kg 计费重量取 96kg(因 96kg > 80kg)。

二、基础运费计算

费率(Rate:航空公司或货代根据航线、货物类型、市场行情等制定(如 CNY 30/kg)。本次作业费率采用分段计算方式:

三、题目说明

本次题目模拟某客户到该航空公司办理一次货运业务的过程: 航空公司提供如下信息: 航班信息(航班号,航班起飞机场所在城市,航班降落机场所在城市,航班 日期,航班最大载重量) 客户填写货运订单并进行支付,需要提供如下信息: ⎫ 客户信息(姓名,电话号码等) ⎫ 货物信息(货物名称,货物包装长、宽、高尺寸,货物重量等) ⎫ 运送信息(发件人姓名、电话、地址,收件人姓名、电话、地址,所选 航班号,订单日期) ⎫ 支付方式(支付宝支付、微信支付) 注:一个货运订单可以运送多件货物,每件货物均需要根据重量及费率单独 计费。 程序需要从键盘依次输入填写订单需要提供的信息,然后分别生成订单信 息报表及货物明细报表。

四、题目要求

本次题目重点考核面向对象设计原则中的单一职责原则、里氏代换原则、开 闭原则以及合成复用原则

输入格式:

按如下顺序分别输入客户信息、货物信息、航班信息以及订单信息。

客户编号

客户姓名

客户电话

客户地址

运送货物数量

[货物编号

货物名称

货物宽度

货物长度

货物高度

货物重量

]//[]内的内容输入次数取决于“运送货物数量”,输入不包含“[]”

航班号

航班起飞机场

航班降落机场

航班日期(格式为YYYY-MM-DD)

航班最大载重量

订单编号

订单日期(格式为YYYY-MM-DD)

发件人地址

发件人姓名

发件人电话

收件人地址

收件人姓名

收件人电话

输出格式:

  • 如果订单中货物重量超过航班剩余载重量,程序输出The flight with flight number:航班号 has exceeded its load capacity and cannot carry the order. ,程序终止运行。
  • 如果航班载重量可以承接该订单,输出如下:

客户:姓名(电话)订单信息如下:

-----------------------------------------

航班号:

订单号:

订单日期:

发件人姓名:

发件人电话:

发件人地址:

收件人姓名:

收件人电话:

收件人地址:

订单总重量(kg):

微信支付金额:

货物明细如下:

-----------------------------------------

明细编号 货物名称 计费重量 计费费率 应交运费

1 ...

2 ...

注:输出中实型数均保留1位小数。

设计与分析

1.分析题目要求

通过题目描述可以得知本次作业所需要的类大致为客户类,货物类,订单类,价钱类,航班类,发件人类,收货人类(发件人和收货人我预想的是整合到客户类中,但思考了感觉不太合适便又单独设置一个类)。

主要逻辑在于rate的计算和判断货物重量取值为体积重量还是实际重量。

剩余在于主函数的输入输出需要根据题目给出模板进行完善。

2.设计框架

首先完成各个类的属性以及是否为抽象类,是谁的父类?是谁的子类?以及各个方法是否合适在某个类中,其次就是对各个输入输出进行匹配,输出该怎么输出以及如何输出正确。

第一次作业分析结果:

基本结构的搭建

构思点在于题目所要求的类以及输入输出。题目的难度不大,所以在给出基本结构后,后续所需要做的就是不断完善填充。

class Customer//用户
{
private String customerID;
private String name;
private String phone;
private String address;
private int goodsnum;

public Customer(String customerID, String name, String phone, String address, int goodsnum) {
this.customerID = customerID;
this.name = name;
this.phone = phone;
this.address = address;
this.goodsnum = goodsnum;
}

public Customer() {
}

}
class Send//发件人
{
private String sendname;
private String sendphone;
private String sendaddress;

public Send(String sendname, String sendphone, String sendaddress) {
this.sendname = sendname;
this.sendphone = sendphone;
this.sendaddress = sendaddress;
}

public Send() {
}

}
class Receive//收件人
{
private String receivename;
private String receivephone;
private String receiveaddress;

public Receive(String receivename, String receivephone, String receiveaddress) {
this.receivename = receivename;
this.receivephone = receivephone;
this.receiveaddress = receiveaddress;
}

public Receive() {
}

}
class Goods//货物
{
private String goodsID;
private String goodsname;
private double wide;
private double length;
private double height;
private double weight;

public Goods(String goodsID, String goodsname, double wide, double length, double height, double weight) {
this.goodsID = goodsID;
this.goodsname = goodsname;
this.wide = wide;
this.length = length;
this.height = height;
this.weight = weight;
}

public Goods() {
}

}
class Flight//航班
{
private String filghtID;
private String startAirport;
private String endAirport;
private String filghtdate;
private double maxWeight;

public Flight(String filghtID, String startAirport, String endAirport, String date, double maxWeight) {
this.filghtID = filghtID;
this.startAirport = startAirport;
this.endAirport = endAirport;
this.filghtdate = date;
this.maxWeight = maxWeight;
}

}
class Orders//订单
{
private String ordersID;
private String orderdate;
private ArrayList<Goods> goods = new ArrayList<>();
private Customer customer;
private Send send;
private Receive receive;

public Orders(String ordersID, String orderdate, ArrayList<Goods> goods, Customer customer, Send send, Receive receive) {
this.ordersID = ordersID;
this.orderdate = orderdate;
this.goods = goods;
this.customer = customer;
this.send = send;
this.receive = receive;
}

public Orders() {
}

}
abstract class Price
{
private double money;
private Goods goods;

public Price() {
}

}

class Wechat extends Price
{
private String payment;

public Wechat(Goods goods) {
super(goods);
}
}

class Alipay extends Price
{
private String payment;

public Alipay(Goods goods) {
super(goods);
}

}

class OrderProcessor
{
}
class Main
{
public static void main(String[] args)
{
}
}

完善代码

Main中的输入输出如下:

Scanner scanner = new Scanner(System.in);
// 客户信息
String customerId = scanner.nextLine();
String customerName = scanner.nextLine();
String customerPhone = scanner.nextLine();
String customerAddress = scanner.nextLine();
int goodsCount = Integer.parseInt(scanner.nextLine());
Customer customer = new Customer(customerId, customerName, customerPhone, customerAddress,goodsCount);

// 货物信息
ArrayList<Goods> goodsList = new ArrayList<>();
for (int i = 0; i < goodsCount; i++) {
String goodsId = scanner.nextLine();
String goodsName = scanner.nextLine();
double width = Double.parseDouble(scanner.nextLine());
double length = Double.parseDouble(scanner.nextLine());
double height = Double.parseDouble(scanner.nextLine());
double weight = Double.parseDouble(scanner.nextLine());
goodsList.add(new Goods(goodsId, goodsName, width, length, height, weight));
}

// 航班信息
String flightID = scanner.nextLine();
String startAirport = scanner.nextLine();
String endAirport = scanner.nextLine();
String flightDate = scanner.nextLine();
double maxWeight = Double.parseDouble(scanner.nextLine());
Flight flight = new Flight(flightID, startAirport, endAirport, flightDate, maxWeight);

// 订单信息
String orderId = scanner.nextLine();
String orderDate = scanner.nextLine();
String senderAddress = scanner.nextLine();
String senderName = scanner.nextLine();
String senderPhone = scanner.nextLine();
String receiverAddress = scanner.nextLine();
String receiverName = scanner.nextLine();
String receiverPhone = scanner.nextLine();
Send send = new Send(senderName,senderPhone,senderAddress);
Receive receive = new Receive(receiverName,receiverPhone,receiverAddress);
Orders order = new Orders(orderId, orderDate,goodsList,customer,send,receive);

// 处理订单
OrderProcessor.processOrder(customer, flight, order);

Rate的计算:

public double Rate() {
double weight = checkWeight();
if (weight < 20) {
return 35;
} else if (weight < 50) {
return 30;
} else if (weight < 100) {
return 25;
} else {
return 15;
}
}

重量的比较:

public double checkWeight() {
double volumeWeight = (goods.getLength() * goods.getWide() * goods.getHeight()) / 6000;
return Math.max(volumeWeight, goods.getWeight());
}

总结

本次作业算法要求不高(几乎没有),主要在于框架的搭建以及类之间关系的运用。本次作业我的问题在于抽象类的使用并不到位以及对于类之间关系的理解不充分,例如price类与支付方式之间不应该是继承关系,这在第二次作业中有所改善。

航空货运管理系统第二次作业分析

作业要求如下:

Tips:本次作业主要是根据第一次作业不断迭代,所以题面差距不大,这里只给出改动部分。

费率(Rate

航空公司或货代根据航线、货物类型、市场行情等制定(如 CNY 30/kg)。

本次作业费率与货物类型有关,货物类型分为普通货物、危险货 物和加急货物三种,其费率分别为:

计算公式:

基础运费 = 计费重量 × 费率 × 折扣率 其中,折扣率是指不同的用户类型针对每个订单的运费可以享受相应的折扣, 在本题中,用户分为个人用户和集团用户,其中个人用户可享受订单运费的 9 折优惠,集团用户可享受订单运费的 8 折优惠。

支付方式

(支付宝支付、微信支付、现金支付)

题目输入格式:

客户类型[可输入项:Individual/Corporate]

客户编号

客户姓名

客户电话

客户地址

货物类型[可输入项:Normal/Expedite/Dangerous]

运送货物数量

[货物编号

货物名称

货物宽度

货物长度

货物高度

货物重量

]//[]内的内容输入次数取决于“运送货物数量”,输入不包含“[]”

航班号

航班起飞机场

航班降落机场

航班日期(格式为YYYY-MM-DD)

航班最大载重量

订单编号

订单日期(格式为YYYY-MM-DD)

发件人地址

发件人姓名

发件人电话

收件人地址

收件人姓名

收件人电话

支付方式[可输入项:Wechat/ALiPay/Cash]

设计与分析:

分析题目:

本次作业是对于第一次作业的迭代,所以基本的类不用过多改变,主要在于rate方法的改动以及其的多态。同时在订单中加入了多件货物,所以在顾客、货物、订单类,输入输出等方面需要改动。总体来说是对于类之间结构的进一步要求。

设计框架:

在原基础之上将顾客类作为父类,添加子类个人客户,团体客户,将货物类改为父类,添加普通货物,危险货物,加急货物子类,并添加现金支付子类。

第二次作业分析结果:

迭代设计:
  1. 在Customer父类中添加方法

public abstract double Discount();

然后在子类中实现如下:

个人:

@Override
public double Discount() {
return 0.9;
}

团体:

@Override
public double Discount() {
return 0.8;
}

  1. 将原Price类中的Rate方法移动到Goods类中以便于子类不同货物Rate计算

public abstract double Rate();

然后在子类中实现如下:

class FormatGoods extends Goods
{
public FormatGoods(String goodsID, String goodsname, double wide, double length, double height, double weight) {
super(goodsID, goodsname, wide, length, height, weight);
}

public FormatGoods() {
}

@Override
public double Rate() {
double weight = checkWeight();
if (weight < 20) {
return 35;
} else if (weight < 50) {
return 30;
} else if (weight < 100) {
return 25;
} else {
return 15;
}
}
}
class DangerGoods extends Goods
{
public DangerGoods(String goodsID, String goodsname, double wide, double length, double height, double weight) {
super(goodsID, goodsname, wide, length, height, weight);
}

public DangerGoods() {
}

@Override
public double Rate() {
double weight = checkWeight();
if (weight < 20) {
return 80;
} else if (weight < 50) {
return 50;
} else if (weight < 100) {
return 30;
} else {
return 20;
}
}
}
class UrgentGoods extends Goods
{
public UrgentGoods(String goodsID, String goodsname, double wide, double length, double height, double weight) {
super(goodsID, goodsname, wide, length, height, weight);
}

public UrgentGoods() {
}

@Override
public double Rate() {
double weight = checkWeight();
if (weight < 20) {
return 60;
} else if (weight < 50) {
return 50;
} else if (weight < 100) {
return 40;
} else {
return 30;
}
}
}

3将支付方式独立出来作为一个类,然后将相应的微信支付,支付宝支付,现金支付继承于它。

abstract class PriceMent
{
private String payment;

public PriceMent() {
}

public String getPayment() {
return payment;
}

public void setPayment(String payment) {
this.payment = payment;
}
}
class WeChat extends PriceMent
{
private String payment;

public WeChat() {
setPayment("微信");
}
}
class Alipay extends PriceMent
{
private String payment;

public Alipay() {
setPayment("支付宝");
}
}
class Cash extends PriceMent
{
private String payment;
public Cash() {
setPayment("现金");
}
}

总结:

.第二次作业更加要求继承与多态的理解实现,对于不同的货物,不同的顾客,不同的支付方式都要做到对应的变化,从本次中更多是对课堂知识的实践运用,更加深刻理解继承与多态在实际中如何实现以及分析。

踩坑心得:

本次作业重点在于继承与多态的实现,所以报错点主要在于子类父类之间关系不明了导致的报错。

  1. 父类子类之间关系不明了导致部分多余

如我在顾客类中有了各个属性的getter以及setter,但在子类中依旧再次设置相同的属性以及getter和setter,导致整个代码看起来臃肿。

  1. super的理解不清晰

在子类方法的实现中即使在构造方法中已经使用了super,但在方法中使用的依旧是this.子类属性,导致后面对于该方法的调用出现了货物无法存入到相应的队列中以及无法读取,导致程序报错。

改进建议:

本次作业主要还是对于这种相对工程量较大的程序经验较少,在前期框架的搭建上十分粗陋,以至于后续不断对于结构改动,对于子类父类的设置也在不断变动。所以在之后的学习中需要加强前期基本结构框架的搭建,这会使得后续迭代更加轻松。

总结:

本次的作业难度不高,加强了对继承与多态知识的实践运用经验,例如子类可以调用父类的方法,以及super在子类的运用。同时加强了对这种较大程序的框架搭建经验,了解了哪个类后续可以作为父类,哪个方法可以抽象化在子类中实现多态。

在后续中会进一步学习接口的使用,实现接口和抽象类的搭配组合,以至于更好对于多态这种形式的实现。

posted @ 2025-05-24 23:05  桦叶梧桐  阅读(30)  评论(0)    收藏  举报