第二次blog作业-航空货运管理系统总结
航空货运管理系统
前言
这两次作业是对继承等知识的考察,但总来说不是非常难,但最大的不同是这两次作业,没有给我们类图作为参考,需要自己设计类来进行作业,在起初,我只是按照输出的不同部分进行分组,其实这是非常不熟练的表现,在五一前后我也对array list不是十分的熟练导致第一次作业完成需要借助ai的帮忙,这也导致我最后完成的十分糊涂,其实我自己也十分清楚我没有对这次作业的核心搞明白,下面我们来详细的分析两次作业
设计与分析
第一次航空货运管理
第一次得知这次的题是没有类图的,我觉得这次的题可能也和上次的电梯一样十分困难,但是我仔细分析了一下题目发现,不是十分的困难,只需要将它给予的输入部分分类就可以十分有条理的设计出框架。
按照上面不同类型我将代码的类分为了
customer,goods,flight,和order类,起初并没有使用继承这个方法,只是建四个独立的类,但是后来自己完成并不会使用Array List这一知识点,下面是我的代码:

第一次代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int customerId = sc.nextInt();
sc.nextLine();
String customerName = sc.nextLine();
String customerPhone = sc.nextLine();
String customerAddress = sc.nextLine();
Customer customer = new Customer(customerId, customerName, customerPhone, customerAddress);
int goodsCount = sc.nextInt();
sc.nextLine();
Goods[] goodsArray = new Goods[goodsCount];
for (int i = 0; i < goodsCount; i++) {
int goodsId = sc.nextInt();
sc.nextLine();
String goodsName = sc.nextLine();
int goodsWidth = sc.nextInt();
int goodsLength = sc.nextInt();
int goodsHeight = sc.nextInt();
double goodsWeight = sc.nextDouble();
sc.nextLine();
goodsArray[i] = new Goods(goodsName, goodsWidth, goodsLength, goodsHeight, goodsWeight);
}
String flightNumber = sc.nextLine();
String departureAirport = sc.nextLine();
String arrivalAirport = sc.nextLine();
String flightDate = sc.nextLine();
int maxLoadCapacity = sc.nextInt();
sc.nextLine();
Flight flight = new Flight(flightNumber, departureAirport, arrivalAirport, flightDate, maxLoadCapacity);
String orderNumber = sc.nextLine();
String orderDate = sc.nextLine();
String senderAddress = sc.nextLine();
String senderName = sc.nextLine();
String senderPhone = sc.nextLine();
String receiverAddress = sc.nextLine();
String receiverName = sc.nextLine();
String receiverPhone = sc.nextLine();
Order order = new Order(orderNumber, orderDate, senderAddress, senderName, senderPhone, receiverAddress, receiverName, receiverPhone);
double totalWeight = 0;
for (Goods goods : goodsArray) {
totalWeight += getChargeableWeight(goods);
}
if (totalWeight > flight.getMaxLoadCapacity()) {
System.out.printf("The flight with flight number:%s has exceeded its load capacity and cannot carry the order.\n", flight.getFlightNumber());
return;
}
System.out.println("客户:" + customer.getCustomerName() + "(" + customer.getCustomerPhone() + ")订单信息如下:");
System.out.println("-----------------------------------------");
System.out.println("航班号:" + flight.getFlightNumber());
System.out.println("订单号:" + order.getOrderNumber());
System.out.println("订单日期:" + order.getOrderDate());
System.out.println("发件人姓名:" + order.getSenderName());
System.out.println("发件人电话:" + order.getSenderPhone());
System.out.println("发件人地址:" + order.getSenderAddress());
System.out.println("收件人姓名:" + order.getReceiverName());
System.out.println("收件人电话:" + order.getReceiverPhone());
System.out.println("收件人地址:" + order.getReceiverAddress());
System.out.println("订单总重量(kg):" + totalWeight);
System.out.println("微信支付金额:" + order.calculatePayment(goodsArray));
System.out.println("\n货物明细如下:");
System.out.println("-----------------------------------------");
System.out.println("明细编号\t货物名称\t计费重量\t计费费率\t应交运费");
for (int i = 0; i < goodsCount; i++) {
Goods goods = goodsArray[i];
double chargeableWeight = getChargeableWeight(goods);
double chargeableRate = calculateChargeableRate(goods);
double freight = chargeableWeight * chargeableRate;
System.out.printf("%d\t%s\t%.1f\t%.1f\t%.1f\n", i + 1, goods.getGoodsName(), chargeableWeight, chargeableRate, freight);
}
}
public static double getChargeableWeight(Goods goods) {
double volumeWeight =0;
if((goods.getGoodsWidth() * goods.getGoodsLength() * goods.getGoodsHeight()) / 6000.0>goods.getGoodsWeight()){
volumeWeight=(goods.getGoodsWidth() * goods.getGoodsLength() * goods.getGoodsHeight()) / 6000.0;
}
else{
volumeWeight = goods.getGoodsWeight();
}
return volumeWeight;
}
public static double calculateChargeableRate(Goods goods) {
double volume = getChargeableWeight(goods);
if (volume < 20) {
return 35.0;
} else if (volume < 50 && volume >= 20) {
return 30.0;
} else if(volume < 100 && volume >= 50) {
return 25.0;
} else{
return 15.0;
}
}
}
class Customer {
private int customerId;
private String customerName;
private String customerPhone;
private String customerAddress;
public Customer() {
}
public Customer(int customerId, String customerName, String customerPhone, String customerAddress) {
this.customerId = customerId;
this.customerName = customerName;
this.customerPhone = customerPhone;
this.customerAddress = customerAddress;
}
// Getter and Setter methods
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerPhone() {
return customerPhone;
}
public void setCustomerPhone(String customerPhone) {
this.customerPhone = customerPhone;
}
public String getCustomerAddress() {
return customerAddress;
}
public void setCustomerAddress(String customerAddress) {
this.customerAddress = customerAddress;
}
}
class Goods {
private String goodsName;
private int goodsWidth;
private int goodsLength;
private int goodsHeight;
private double goodsWeight;
public Goods() {
}
public Goods(String goodsName, int goodsWidth, int goodsLength, int goodsHeight, double goodsWeight) {
this.goodsName = goodsName;
this.goodsWidth = goodsWidth;
this.goodsLength = goodsLength;
this.goodsHeight = goodsHeight;
this.goodsWeight = goodsWeight;
}
// Getter and Setter methods
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public int getGoodsWidth() {
return goodsWidth;
}
public void setGoodsWidth(int goodsWidth) {
this.goodsWidth = goodsWidth;
}
public int getGoodsLength() {
return goodsLength;
}
public void setGoodsLength(int goodsLength) {
this.goodsLength = goodsLength;
}
public int getGoodsHeight() {
return goodsHeight;
}
public void setGoodsHeight(int goodsHeight) {
this.goodsHeight = goodsHeight;
}
public double getGoodsWeight() {
return goodsWeight;
}
public void setGoodsWeight(double goodsWeight) {
this.goodsWeight = goodsWeight;
}
}
class Flight {
private String flightNumber;
private String departureAirport;
private String arrivalAirport;
private String flightDate;
private int maxLoadCapacity;
public Flight() {
}
public Flight(String flightNumber, String departureAirport, String arrivalAirport, String flightDate, int maxLoadCapacity) {
this.flightNumber = flightNumber;
this.departureAirport = departureAirport;
this.arrivalAirport = arrivalAirport;
this.flightDate = flightDate;
this.maxLoadCapacity = maxLoadCapacity;
}
// Getter and Setter methods
public String getFlightNumber() {
return flightNumber;
}
public void setFlightNumber(String flightNumber) {
this.flightNumber = flightNumber;
}
public String getDepartureAirport() {
return departureAirport;
}
public void setDepartureAirport(String departureAirport) {
this.departureAirport = departureAirport;
}
public String getArrivalAirport() {
return arrivalAirport;
}
public void setArrivalAirport(String arrivalAirport) {
this.arrivalAirport = arrivalAirport;
}
public String getFlightDate() {
return flightDate;
}
public void setFlightDate(String flightDate) {
this.flightDate = flightDate;
}
public int getMaxLoadCapacity() {
return maxLoadCapacity;
}
public void setMaxLoadCapacity(int maxLoadCapacity) {
this.maxLoadCapacity = maxLoadCapacity;
}
}
class Order {
private String orderNumber;
private String orderDate;
private String senderAddress;
private String senderName;
private String senderPhone;
private String receiverAddress;
private String receiverName;
private String receiverPhone;
public Order() {
}
public Order(String orderNumber, String orderDate, String senderAddress, String senderName, String senderPhone, String receiverAddress, String receiverName, String receiverPhone) {
this.orderNumber = orderNumber;
this.orderDate = orderDate;
this.senderAddress = senderAddress;
this.senderName = senderName;
this.senderPhone = senderPhone;
this.receiverAddress = receiverAddress;
this.receiverName = receiverName;
this.receiverPhone = receiverPhone;
}
// Getter and Setter methods
public String getOrderNumber() {
return orderNumber;
}
public void setOrderNumber(String orderNumber) {
this.orderNumber = orderNumber;
}
public String getOrderDate() {
return orderDate;
}
public void setOrderDate(String orderDate) {
this.orderDate = orderDate;
}
public String getSenderAddress() {
return senderAddress;
}
public void setSenderAddress(String senderAddress) {
this.senderAddress = senderAddress;
}
public String getSenderName() {
return senderName;
}
public void setSenderName(String senderName) {
this.senderName = senderName;
}
public String getSenderPhone() {
return senderPhone;
}
public void setSenderPhone(String senderPhone) {
this.senderPhone = senderPhone;
}
public String getReceiverAddress() {
return receiverAddress;
}
public void setReceiverAddress(String receiverAddress) {
this.receiverAddress = receiverAddress;
}
public String getReceiverName() {
return receiverName;
}
public void setReceiverName(String receiverName) {
this.receiverName = receiverName;
}
public String getReceiverPhone() {
return receiverPhone;
}
public void setReceiverPhone(String receiverPhone) {
this.receiverPhone = receiverPhone;
}
public double calculatePayment(Goods[] goodsArray) {
double totalPayment = 0;
for (Goods goods : goodsArray) {
double chargeableWeight = Main.getChargeableWeight(goods);
double chargeableRate = Main.calculateChargeableRate(goods);
totalPayment += chargeableWeight * chargeableRate;
}
return totalPayment;
}
}
可见编写的十分生疏,并没有使用复杂的知识点,并且在最后输出的地方也是用的简单的println,甚至有些类中的方法并没有使用
下面是我代码的分析结果
代码分析
Metrics Details For File 'Main.java'
--------------------------------------------------------------------------------------------
Parameter Value
========= =====
Project Directory D:\idl\pta\src\
Project Name 11
Checkpoint Name Baseline
File Name Main.java
Lines 375
Statements 229
Percent Branch Statements 4.4
Method Call Statements 53
Percent Lines with Comments 1.1
Classes and Interfaces 5
Methods per Class 11.20
Average Statements per Method 2.59
Line Number of Most Complex Method 93
Name of Most Complex Method Main.calculateChargeableRate()
Maximum Complexity 7
Line Number of Deepest Block 18
Maximum Block Depth 3
Average Block Depth 1.72
Average Complexity 1.21
--------------------------------------------------------------------------------------------
Most Complex Methods in 5 Class(es): Complexity, Statements, Max Depth, Calls
Customer.Customer() 1, 4, 2, 0
Customer.Customer() 1, 0, 0, 0
Customer.getCustomerAddress() 1, 1, 2, 0
Customer.getCustomerId() 1, 1, 2, 0
Customer.getCustomerName() 1, 1, 2, 0
Customer.getCustomerPhone() 1, 1, 2, 0
Customer.setCustomerAddress() 1, 1, 2, 0
Customer.setCustomerId() 1, 1, 2, 0
Customer.setCustomerName() 1, 1, 2, 0
Customer.setCustomerPhone() 1, 1, 2, 0
Flight.Flight() 1, 5, 2, 0
Flight.Flight() 1, 0, 0, 0
Flight.getArrivalAirport() 1, 1, 2, 0
Flight.getDepartureAirport() 1, 1, 2, 0
Flight.getFlightDate() 1, 1, 2, 0
Flight.getFlightNumber() 1, 1, 2, 0
Flight.getMaxLoadCapacity() 1, 1, 2, 0
Flight.setArrivalAirport() 1, 1, 2, 0
Flight.setDepartureAirport() 1, 1, 2, 0
Flight.setFlightDate() 1, 1, 2, 0
Flight.setFlightNumber() 1, 1, 2, 0
Flight.setMaxLoadCapacity() 1, 1, 2, 0
Goods.getGoodsHeight() 1, 1, 2, 0
Goods.getGoodsLength() 1, 1, 2, 0
Goods.getGoodsName() 1, 1, 2, 0
Goods.getGoodsWeight() 1, 1, 2, 0
Goods.getGoodsWidth() 1, 1, 2, 0
Goods.Goods() 1, 5, 2, 0
Goods.Goods() 1, 0, 0, 0
Goods.setGoodsHeight() 1, 1, 2, 0
Goods.setGoodsLength() 1, 1, 2, 0
Goods.setGoodsName() 1, 1, 2, 0
Goods.setGoodsWeight() 1, 1, 2, 0
Goods.setGoodsWidth() 1, 1, 2, 0
Main.calculateChargeableRate() 7, 9, 3, 1
Main.getChargeableWeight() 2, 5, 3, 4
Main.main() 5, 59, 3, 46
Order.calculatePayment() 2, 6, 3, 2
Order.getOrderDate() 1, 1, 2, 0
Order.getOrderNumber() 1, 1, 2, 0
Order.getReceiverAddress() 1, 1, 2, 0
Order.getReceiverName() 1, 1, 2, 0
Order.getReceiverPhone() 1, 1, 2, 0
Order.getSenderAddress() 1, 1, 2, 0
Order.getSenderName() 1, 1, 2, 0
Order.getSenderPhone() 1, 1, 2, 0
Order.Order() 1, 8, 2, 0
Order.Order() 1, 0, 0, 0
Order.setOrderDate() 1, 1, 2, 0
Order.setOrderNumber() 1, 1, 2, 0
Order.setReceiverAddress() 1, 1, 2, 0
Order.setReceiverName() 1, 1, 2, 0
Order.setReceiverPhone() 1, 1, 2, 0
Order.setSenderAddress() 1, 1, 2, 0
Order.setSenderName() 1, 1, 2, 0
Order.setSenderPhone() 1, 1, 2, 0
--------------------------------------------------------------------------------------------
Block Depth Statements
0 6
1 78
2 119
3 26
4 0
5 0
6 0
7 0
8 0
9+ 0
--------------------------------------------------------------------------------------------

分析结果表示:类和接口数量:有 5 个。平均每个类的方法数:11.2 个 。平均每个方法的语句数:2.59 条。最复杂方法:是 Main.calculateChargeableRate() ,其行数为 93 行,复杂度达 7 ,复杂度较高,可能维护起来较困难。最大代码块深度:为 3 ,平均代码块深度 1.72 。在可读性和可维护性上存在明显不足,这其实是我代码存在的问题。
第二次航空货运管理系统
这一次我吸取的上次的教训,但是这次一次的题目我觉得相较于上次一片空白来说我熟练了好多,因为大体框架我并没有修改,只是我运用自己的见解,在部分类中添加了有关其“type”的变量,我在这其中犯得最傻的问题可能就是我在验证两个字符串是否相同时用的是“==”这种方式,不知道是我学术不精,还是我对于c语言的习惯,始终在这里报错,我交给ai后我才修改了这个问题,下面是我的代码:

第二次代码
import java.util.Scanner;
import java.util.InputMismatchException;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 读取客户信息
String customertype = sc.nextLine();
int customerId = sc.nextInt();
sc.nextLine();
String customerName = sc.nextLine();
String customerPhone = sc.nextLine();
String customerAddress = sc.nextLine();
Customer customer = new Customer(customertype, customerId, customerName, customerPhone, customerAddress);
String goodstype = sc.nextLine();
int goodsCount = 0;
try {
goodsCount = sc.nextInt();
} catch (InputMismatchException e) {
System.out.println("Error: Goods count must be an integer.");
sc.next(); // 清除错误输入
return;
}
sc.nextLine(); // 清除换行符
Goods[] goodsArray = new Goods[goodsCount];
for (int i = 0; i < goodsCount; i++) {
int goodsId = 0;
try {
goodsId = sc.nextInt();
} catch (InputMismatchException e) {
System.out.println("Error: Goods ID must be an integer.");
sc.next(); // 清除错误输入
return;
}
sc.nextLine(); // 清除换行符
String goodsName = sc.nextLine();
int goodsWidth = 0, goodsLength = 0, goodsHeight = 0;
try {
goodsWidth = sc.nextInt();
goodsLength = sc.nextInt();
goodsHeight = sc.nextInt();
} catch (InputMismatchException e) {
System.out.println("Error: Goods dimensions must be integers.");
sc.next(); // 清除错误输入
return;
}
double goodsWeight = 0.0;
try {
goodsWeight = sc.nextDouble();
} catch (InputMismatchException e) {
System.out.println("Error: Goods weight must be a number.");
sc.next(); // 清除错误输入
return;
}
sc.nextLine(); // 清除换行符
goodsArray[i] = new Goods(goodstype, goodsName, goodsWidth, goodsLength, goodsHeight, goodsWeight);
}
// 读取航班信息
String flightNumber = sc.nextLine();
String departureAirport = sc.nextLine();
String arrivalAirport = sc.nextLine();
String flightDate = sc.nextLine();
int maxLoadCapacity = 0;
try {
maxLoadCapacity = sc.nextInt();
} catch (InputMismatchException e) {
System.out.println("Error: Max load capacity must be an integer.");
sc.next(); // 清除错误输入
return;
}
sc.nextLine(); // 清除换行符
Flight flight = new Flight(flightNumber, departureAirport, arrivalAirport, flightDate, maxLoadCapacity);
// 读取订单信息
String orderNumber = sc.nextLine();
String orderDate = sc.nextLine();
String senderAddress = sc.nextLine();
String senderName = sc.nextLine();
String senderPhone = sc.nextLine();
String receiverAddress = sc.nextLine();
String receiverName = sc.nextLine();
String receiverPhone = sc.nextLine();
String payway = sc.nextLine();
Order order = new Order(orderNumber, orderDate, senderAddress, senderName, senderPhone, receiverAddress, receiverName, receiverPhone, payway, customer);
// 计算总重量
double totalWeight = 0;
for (Goods goods : goodsArray) {
totalWeight += getChargeableWeight(goods);
}
// 检查航班载重是否超出
if (totalWeight > flight.getMaxLoadCapacity()) {
System.out.printf("The flight with flight number:%s has exceeded its load capacity and cannot carry the order.\n", flight.getFlightNumber());
return;
}
// 输出客户和订单信息
System.out.println("客户:" + customer.getCustomerName() + "(" + customer.getCustomerPhone() + ")订单信息如下:");
System.out.println("-----------------------------------------");
System.out.println("航班号:" + flight.getFlightNumber());
System.out.println("订单号:" + order.getOrderNumber());
System.out.println("订单日期:" + order.getOrderDate());
System.out.println("发件人姓名:" + order.getSenderName());
System.out.println("发件人电话:" + order.getSenderPhone());
System.out.println("发件人地址:" + order.getSenderAddress());
System.out.println("收件人姓名:" + order.getReceiverName());
System.out.println("收件人电话:" + order.getReceiverPhone());
System.out.println("收件人地址:" + order.getReceiverAddress());
System.out.println("订单总重量(kg):" + totalWeight);
System.out.println(order.getPayway() + "支付金额:" + order.calculatePayment(goodsArray));
// 输出货物明细
System.out.println("\n货物明细如下:");
System.out.println("-----------------------------------------");
System.out.println("明细编号\t货物名称\t计费重量\t计费费率\t应交运费");
for (int i = 0; i < goodsCount; i++) {
Goods goods = goodsArray[i];
double chargeableWeight = getChargeableWeight(goods);
double chargeableRate = calculateChargeableRate(goods);
double freight = chargeableWeight * chargeableRate;
System.out.printf("%d\t%s\t%.1f\t%.1f\t%.1f\n", i + 1, goods.getGoodsName(), chargeableWeight, chargeableRate, freight);
}
}
public static double getChargeableWeight(Goods goods) {
double volumeWeight = Math.max((goods.getGoodsWidth() * goods.getGoodsLength() * goods.getGoodsHeight()) / 6000.0, goods.getGoodsWeight());
return volumeWeight;
}
public static double calculateChargeableRate(Goods goods) {
double volume = getChargeableWeight(goods);
switch (goods.getGoodstype()) {
case "Normal":
return volume < 20 ? 35.0 : volume < 50 ? 30.0 : volume < 100 ? 25.0 : 15.0;
case "Dangerous":
return volume < 20 ? 80.0 : volume < 50 ? 50.0 : volume < 100 ? 30.0 : 20.0;
case "Expedite":
return volume < 20 ? 60.0 : volume < 50 ? 50.0 : volume < 100 ? 40.0 : 30.0;
default:
return 0;
}
}
}
class Customer {
private String customertype;
private int customerId;
private String customerName;
private String customerPhone;
private String customerAddress;
public Customer(String customertype, int customerId, String customerName, String customerPhone, String customerAddress) {
this.customertype = customertype;
this.customerId = customerId;
this.customerName = customerName;
this.customerPhone = customerPhone;
this.customerAddress = customerAddress;
}
public int getCustomerId() {
return customerId;
}
public String getCustomerName() {
return customerName;
}
public String getCustomerPhone() {
return customerPhone;
}
public String getCustomerAddress() {
return customerAddress;
}
public String getCustomertype() {
return customertype;
}
}
class Goods {
private String goodstype;
private String goodsName;
private int goodsWidth;
private int goodsLength;
private int goodsHeight;
private double goodsWeight;
public Goods(String goodstype, String goodsName, int goodsWidth, int goodsLength, int goodsHeight, double goodsWeight) {
this.goodstype = goodstype;
this.goodsName = goodsName;
this.goodsWidth = goodsWidth;
this.goodsLength = goodsLength;
this.goodsHeight = goodsHeight;
this.goodsWeight = goodsWeight;
}
public String getGoodstype() {
return goodstype;
}
public String getGoodsName() {
return goodsName;
}
public int getGoodsWidth() {
return goodsWidth;
}
public int getGoodsLength() {
return goodsLength;
}
public int getGoodsHeight() {
return goodsHeight;
}
public double getGoodsWeight() {
return goodsWeight;
}
}
class Flight {
private String flightNumber;
private String departureAirport;
private String arrivalAirport;
private String flightDate;
private int maxLoadCapacity;
public Flight(String flightNumber, String departureAirport, String arrivalAirport, String flightDate, int maxLoadCapacity) {
this.flightNumber = flightNumber;
this.departureAirport = departureAirport;
this.arrivalAirport = arrivalAirport;
this.flightDate = flightDate;
this.maxLoadCapacity = maxLoadCapacity;
}
public String getFlightNumber() {
return flightNumber;
}
public int getMaxLoadCapacity() {
return maxLoadCapacity;
}
}
class Order {
private String orderNumber;
private String orderDate;
private String senderAddress;
private String senderName;
private String senderPhone;
private String receiverAddress;
private String receiverName;
private String receiverPhone;
private String payway;
private Customer customer;
public Order(String orderNumber, String orderDate, String senderAddress, String senderName, String senderPhone, String receiverAddress, String receiverName, String receiverPhone, String payway, Customer customer) {
this.orderNumber = orderNumber;
this.orderDate = orderDate;
this.senderAddress = senderAddress;
this.senderName = senderName;
this.senderPhone = senderPhone;
this.receiverAddress = receiverAddress;
this.receiverName = receiverName;
this.receiverPhone = receiverPhone;
this.payway = payway;
this.customer = customer;
}
public String getOrderNumber() {
return orderNumber;
}
public String getOrderDate() {
return orderDate;
}
public String getSenderName() {
return senderName;
}
public String getSenderPhone() {
return senderPhone;
}
public String getSenderAddress() {
return senderAddress;
}
public String getReceiverName() {
return receiverName;
}
public String getReceiverPhone() {
return receiverPhone;
}
public String getReceiverAddress() {
return receiverAddress;
}
public String getPayway() {
if ("Wechat".equals(payway)) {
return "微信";
} else if ("ALiPay".equals(payway)) {
return "支付宝";
} else if ("Cash".equals(payway)) {
return "现金";
}
return payway;
}
public double calculatePayment(Goods[] goodsArray) {
double totalPayment = 0;
for (Goods goods : goodsArray) {
double chargeableWeight = Main.getChargeableWeight(goods);
double chargeableRate = Main.calculateChargeableRate(goods);
totalPayment += chargeableWeight * chargeableRate;
}
if ("Individual".equals(customer.getCustomertype())) {
totalPayment *= 0.9;
} else if ("Corporate".equals(customer.getCustomertype())) {
totalPayment *= 0.8;
}
return totalPayment;
}
}
其实我在第二次的作业中并没有加入其他的类,我只是在原有的基础上添加变量改动的很小,但其实我知道我这样导致我的代码,可改动的空间就很小,这样维护性也会很差,我并没有使用继承和抽象类的方法,下面是我这次代码的分析结果:
代码分析
Metrics Details For File 'Main.java'
--------------------------------------------------------------------------------------------
Parameter Value
========= =====
Project Directory D:\idl\pta\src\
Project Name a
Checkpoint Name Baseline
File Name Main.java
Lines 333
Statements 209
Percent Branch Statements 9.1
Method Call Statements 63
Percent Lines with Comments 4.5
Classes and Interfaces 5
Methods per Class 5.80
Average Statements per Method 6.48
Line Number of Most Complex Method 5
Name of Most Complex Method Main.main()
Maximum Complexity 8
Line Number of Deepest Block 30
Maximum Block Depth 4
Average Block Depth 1.85
Average Complexity 1.27
--------------------------------------------------------------------------------------------
Most Complex Methods in 5 Class(es): Complexity, Statements, Max Depth, Calls
Customer.Customer() 1, 5, 2, 0
Customer.getCustomerAddress() 1, 1, 2, 0
Customer.getCustomerId() 1, 1, 2, 0
Customer.getCustomerName() 1, 1, 2, 0
Customer.getCustomerPhone() 1, 1, 2, 0
Customer.getCustomertype() 1, 1, 2, 0
Flight.Flight() 1, 5, 2, 0
Flight.getFlightNumber() 1, 1, 2, 0
Flight.getMaxLoadCapacity() 1, 1, 2, 0
Goods.getGoodsHeight() 1, 1, 2, 0
Goods.getGoodsLength() 1, 1, 2, 0
Goods.getGoodsName() 1, 1, 2, 0
Goods.getGoodstype() 1, 1, 2, 0
Goods.getGoodsWeight() 1, 1, 2, 0
Goods.getGoodsWidth() 1, 1, 2, 0
Goods.Goods() 1, 6, 2, 0
Main.main() 8, 69, 4, 43
Order.getOrderDate() 1, 1, 2, 0
Order.getOrderNumber() 1, 1, 2, 0
Order.getReceiverAddress() 1, 1, 2, 0
Order.getReceiverName() 1, 1, 2, 0
Order.getReceiverPhone() 1, 1, 2, 0
Order.getSenderAddress() 1, 1, 2, 0
Order.getSenderName() 1, 1, 2, 0
Order.getSenderPhone() 1, 1, 2, 0
Order.Order() 1, 10, 2, 0
--------------------------------------------------------------------------------------------
Block Depth Statements
0 9
1 67
2 94
3 25
4 14
5 0
6 0
7 0
8 0
9+ 0
--------------------------------------------------------------------------------------------

浙公网安备 33010602011771号