第二次博客作业-航空货物管理系统
航空货运管理系统总结
前言
1.知识点总结:这次迭代作业主要考察了继承的正确使用,面向对象原则的正确运用,运用了面向对象原则中的单一职责原则,迪米特法则,里氏代换原则、
开闭原则以及合成复用原则、依赖倒转原则等原则的正确运用,而且还考察了类设计的正确性,并且要考虑现实情况和实际需求。第一次作业是情况比较单
一,不用考虑货物的类型,客户的类型和支付方式,做起来较为简单易上手,但不能因此而胡乱设计自己的类而使得代码的可扩展性下降从而对第二次的迭代
造成不必要的麻烦,第二次迭代作业则是现实生活中客户需求的增加或改变,是在第一次的基础上进行修改。
2.题量难度分析:总体题量适中,有充足的时间来进行类设计和具体代码的实现和一些错误的修改。题目在理解上并不困难,且要实现内容也贴近生活,要注意
的是输出格式的控制和一些比较计算对象的确定,并且要设计好类与类之间的关系,类要干好自己该干的事不该干的事不要去干。
设计与分析
第一次航空货运源代码分析
点击查看代码
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String>customerlist = new ArrayList<>();
Scanner input = new Scanner(System.in);
String data;
int num;
for(int i = 0;i<4;i++ ){
data = input.nextLine();
customerlist.add(data);
}//读取客户信息
Customer customer = new Customer(customerlist.get(0), customerlist.get(1), customerlist.get(2), customerlist.get(3) );
num = input.nextInt();
input.nextLine();
String bh ;
String name ;
double width ;
double length ;
double height ;
double weight ;
Goods goods = new Goods();
for(int i=0;i<num;i++){
goods.setI(i);
if(i!=0){
input.nextLine();
}
bh = input.nextLine();
name = input.nextLine();
width = input.nextDouble();
length = input.nextDouble();
height = input.nextDouble();
weight = input.nextDouble();
goods.setBh(bh);
goods.setName(name);
goods.setWidth(width);
goods.setLength(length);
goods.setHeight(height);
goods.setWeight(weight);
}//读取货物信息
if(num!=0){
input.nextLine();
}
String airlinenum = input.nextLine();
String airlinefly = input.nextLine();
String airlineland = input.nextLine();
String date = input.nextLine();
double maxheight = input.nextDouble();
input.nextLine();
String ordernum = input.nextLine();//订单编号
String orderdate = input.nextLine();
goods.setNum(num);
String sendadress = input.nextLine();
String sendname = input.nextLine();
String sendphonenumber = input.nextLine();
String radress = input.nextLine();
String rname = input.nextLine();
String rphonenumber = input.nextLine();
Airline airline = new Airline(airlinenum, airlinefly, airlineland,date , maxheight ) ;
Order order = new Order(ordernum, orderdate);
Senderpeople senderpeople = new Senderpeople(sendadress, sendname, sendphonenumber );
Recipientpeople recipientpeople = new Recipientpeople(radress, rname, rphonenumber );
Pay pay;
WechatPay wechatPay = new WechatPay();
Agent agent = new Agent(customer,goods,airline,order,senderpeople,recipientpeople,wechatPay);
double allweight = agent.Calculateweight();
if(allweight>airline.getMaxheight()){
System.out.println("The flight with flight number:"+airline.getNum()+" has exceeded its load capacity and cannot carry the order.");
}
else{
agent.print();
}
}
}
class Customer {
private String num;//客户编号
private String name;//客户姓名
private String phonenumber;//客户电话
private String adress;//客户地址
public Customer(String num,String name,String phonenumber,String adress) {
this.num = num;
this.name = name;
this.phonenumber = phonenumber;
this.adress = adress;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
}
class Goods {
private String[] bh = new String[1000];
private String[] name = new String[1000];
private double[] width = new double[1000];
private double[] length = new double[1000];
private double[] height = new double[1000];
private double[] weight = new double[1000];
private double zweight;
private double price;
private int num; // 货物数量
private int i;
public Goods() {
}
public String getName() {
return name[i];
}
public double getWidth() {
return width[i];
}
public double getLength() {
return length[i];
}
public double getHeight() {
return height[i];
}
public double getWeight() {
return weight[i];
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public void setName(String name) {
this.name[i] = name;
}
public void setWidth(double width) {
this.width[i] = width;
}
public void setLength(double length) {
this.length[i] = length;
}
public void setHeight(double height) {
this.height[i] = height;
}
public void setWeight(double weight) {
this.weight[i] = weight;
}
public String[] getBh() {
return bh;
}
public void setBh(String bh) {
this.bh[i] = bh;
}
public double getZweight() {
return zweight;
}
public void setZweight(double zweight) {
this.zweight = zweight;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public void SelectWeight() {
double v;
v = getWidth() * getLength() * getHeight() / 6000;
if (v > getWeight()) {
setZweight(v);
} else {
setZweight(getWeight());
}
}
public void CalculatePrice() {
double mweight = getZweight();
double price;
if (mweight >= 100) {
price = mweight * 15.0;
} else if (mweight >= 50) {
price = mweight * 25.0;
} else if (mweight >= 20) {
price = mweight * 30.0;
} else {
price = mweight * 35.0;
}
setPrice(price);
}
public double getRate() {
double mweight = getZweight();
double rate;
if (mweight >= 100) {
rate = 15.0;
} else if (mweight >= 50) {
rate = 25.0;
} else if (mweight >= 20) {
rate = 30.0;
} else {
rate = 35.0;
}
return rate;
}
}
class Agent {
Customer customer;
Goods goods;
Airline airline;
Order order;
People people;
Senderpeople senderpeople;
Recipientpeople recipientpeople;
Pay pay;
WechatPay wechatPay;
public Agent(Customer customer, Goods goods, Airline airline,Order order, Senderpeople senderpeople, Recipientpeople recipientpeople, WechatPay wechatPay) {
this.customer = customer;
this.goods = goods;
this.airline = airline;
this.order = order;
this.senderpeople = senderpeople;
this.recipientpeople = recipientpeople;
this.wechatPay = wechatPay;
}
public double Calculateweight(){
double allweight = 0;
int num = goods.getNum();
for(int i = 0;i<num;i++){
goods.setI(i);
goods.SelectWeight();
allweight= allweight + goods.getZweight();
}
return allweight;
}
public double Calculateprice(){
double allprice = 0;
int num = goods.getNum();
double zweight = 0;
for(int i =0;i<num;i++){
goods.setI(i);
goods.SelectWeight();
zweight = goods.getZweight();
goods.CalculatePrice();
allprice =allprice+goods.getPrice();
}
return allprice;
}
public void print(){
double allweight = Calculateweight();
System.out.println("客户:"+customer.getName()+"("+customer.getPhonenumber()+")"+"订单信息如下:");
System.out.println("-----------------------------------------");
System.out.println("航班号:"+airline.getNum());
System.out.println("订单号:"+order.getNum());
System.out.println("订单日期:"+order.getDate());
people =senderpeople;
System.out.println("发件人姓名:"+people.getName());
System.out.println("发件人电话:"+people.getphoneNumber());
System.out.println("发件人地址:"+people.getAdress());
people = recipientpeople;
System.out.println("收件人姓名:"+people.getName());
System.out.println("收件人电话:"+people.getphoneNumber());
System.out.println("收件人地址:"+people.getAdress());
System.out.printf("订单总重量(kg):%.1f\n",allweight);
double allprice = Calculateprice();
pay =wechatPay;
System.out.printf("%s%.1f\n",pay.getPay(),allprice);
System.out.printf("\n");
System.out.println("货物明细如下:");
System.out.println("-----------------------------------------");
System.out.println("明细编号\t货物名称\t计费重量\t计费费率\t应交运费");
for (int i =0;i<goods.getNum();i++){
goods.setI(i);
goods.SelectWeight();
goods.CalculatePrice();
System.out.printf("%d\t%s\t%.1f\t%.1f\t%.1f\n",i+1,goods.getName(),goods.getZweight(),goods.getRate(),goods.getPrice());
}
}
}
abstract class Pay {
public abstract String getPay();
}
class WechatPay extends Pay {
@Override
public String getPay(){
return "微信支付金额:";
}
}
class AlPay extends Pay{
@Override
public String getPay(){
return "支付宝支付金额:";
}
}
class Airline {
private String num ;
private String date;
private double maxheight;
public String airlinefly;
public String airlineland;
public Airline(){
}
public Airline(String num, String airlinefly,String airlineland,String date, double maxheight) {
this.num = num;
this.date = date;
this.maxheight = maxheight;
this.airlinefly = airlinefly;
this.airlineland = airlineland;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public double getMaxheight() {
return maxheight;
}
public void setMaxheight(double maxheight) {
this.maxheight = maxheight;
}
public String getAirlinefly() {
return airlinefly;
}
public void setAirlinefly(String airlinefly) {
this.airlinefly = airlinefly;
}
public String getAirlineland() {
return airlineland;
}
public void setAirlineland(String airlineland) {
this.airlineland = airlineland;
}
}
class Order {
private String num;//订单编号
private String date;//订单日期
public Order(String num, String date) {
this.num = num;
this.date = date;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
abstract class People {
public abstract String getAdress();
public abstract String getName();
public abstract String getphoneNumber();
}
class Senderpeople extends People {
private String adress;
private String name;
private String phonenumber;
public Senderpeople(String adress, String name, String phonenumber) {
this.adress = adress;
this.name = name;
this.phonenumber = phonenumber;
}
@Override
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
@Override
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String getphoneNumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
}
class Recipientpeople extends People {
private String adress;
private String name;
private String phonenumber;
public Recipientpeople(String adress, String name, String phonenumber) {
this.adress = adress;
this.name = name;
this.phonenumber = phonenumber;
}
@Override
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
@Override
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String getphoneNumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
}
航空货运管理分析
- 首先计算出计费重量和,与航班总载重量进行比较
- 如果能装下则根据每件货物的计费重量选择费率计算费用,后输出结果
否则直接输出不能装载结束
类图

类设计分析
在第一次类设计中我把大多数计算都放在Agent这一个控制类中,
而且结合实际生活缺少了一个订单明细类,导致其有些不符合实际,
计算货物的费用应该放在订单明细类中
代码分析

分析与心得
分析
- 最大代码块深度 4 。
- 平均代码块深度 1.84 。
- 平均复杂度 1.50 。
- 分支语句占比 8.1%
心得
分支语句占比相对较低,意味着代码中条件判断(如 if - else、switch 等)的使用不是特别频繁,代码逻辑相对较为线性,更容易理解和维护。
平均代码块深度不算高,说明大部分代码块的嵌套情况不严重,最大深度为 4 ,说明代码中存在一定深度的嵌套结构(如循环或条件语句嵌套),
过深的嵌套会使代码可读性变差,可考虑通过提取方法等方式进行优化。
第二次航空货运迭代源代码分析
点击查看代码
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String> customerlist = new ArrayList<>();
Scanner input = new Scanner(System.in);
String data;
int num;
for (int i = 0; i < 5; i++) {
data = input.nextLine();
customerlist.add(data);
}//读取客户信息
Customer customer = new Customer(customerlist.get(0), customerlist.get(1), customerlist.get(2), customerlist.get(3),customerlist.get(4));
String goodstype = input.nextLine();
num = input.nextInt();
input.nextLine();
String bh;
String name;
double width;
double length;
double height;
double weight;
Goods goods;
if (goodstype.equals("Normal")) {
goods = new NGoods();
}
else if (goodstype.equals("Expedite")) {
goods = new EGoods();
}
else {
goods = new DGoods();
}
goods.setType(goodstype);
for (int i = 0; i < num; i++) {
goods.setI(i);
if (i != 0) {
input.nextLine();
}
bh = input.nextLine();
name = input.nextLine();
width = input.nextDouble();
length = input.nextDouble();
height = input.nextDouble();
weight = input.nextDouble();
goods.setBh(bh);
goods.setName(name);
goods.setWidth(width);
goods.setLength(length);
goods.setHeight(height);
goods.setWeight(weight);
}//读取货物信息
if (num != 0) {
input.nextLine();
}
String airlinenum = input.nextLine();
String airlinefly = input.nextLine();
String airlineland = input.nextLine();
String date = input.nextLine();
double maxheight = input.nextDouble();
input.nextLine();
String ordernum = input.nextLine();//订单编号
String orderdate = input.nextLine();
goods.setNum(num);
String sendadress = input.nextLine();
String sendname = input.nextLine();
String sendphonenumber = input.nextLine();
String radress = input.nextLine();
String rname = input.nextLine();
String rphonenumber = input.nextLine();
String paytype = input.nextLine();
Airline airline = new Airline(airlinenum, airlinefly, airlineland, date, maxheight);
Order order = new Order(ordernum, orderdate);
Senderpeople Senderpeople = new Senderpeople(sendadress, sendname, sendphonenumber);
Recipientpeople recipientpeople = new Recipientpeople(radress, rname, rphonenumber);
Pay pay;
if (paytype.equals("Wechat")) {
pay = new WechatPay();
}
else if (paytype.equals("ALiPay")) {
pay = new AlPay();
}
else {
pay = new XianjPay();
}
Ordermx ordermx = new Ordermx(goods,customer);
Agent agent = new Agent(customer, goods, airline, order, Senderpeople, recipientpeople, pay, ordermx);
double allweight = agent.Calculateweight();
if (allweight > airline.getMaxheight()) {
System.out.println("The flight with flight number:" + airline.getNum() + " has exceeded its load capacity and cannot carry the order.");
} else {
agent.print();
}
}
}
class Agent {
Customer customer;
Goods goods;
Airline airline;
Order order;
People people;
Senderpeople Senderpeople;
Recipientpeople recipientpeople;
Pay pay;
Ordermx ordermx;
public Agent(Customer customer, Goods goods, Airline airline, Order order, Senderpeople Senderpeople, Recipientpeople recipientpeople, Pay pay,Ordermx ordermx) {
this.customer = customer;
this.goods = goods;
this.airline = airline;
this.order = order;
this.Senderpeople = Senderpeople;
this.recipientpeople = recipientpeople;
this.pay = pay;
this.ordermx = ordermx;
}
public double Calculateweight(){
double allweight = 0;
int num = goods.getNum();
for(int i = 0;i<num;i++){
goods.setI(i);
goods.SelectWeight();
allweight= allweight + goods.getZweight();
}
return allweight;
}
public double Calculateprice(){
double allprice = 0;
int num = goods.getNum();
double zweight = 0;
for(int i =0;i<num;i++){
goods.setI(i);
goods.SelectWeight();
ordermx.CalculateDiscount();
allprice =allprice+ordermx.getPrice();
}
double discount = ordermx.getDiscount();
allprice = allprice*discount;
return allprice;
}
public void print(){
double allweight = Calculateweight();
System.out.println("客户:"+customer.getName()+"("+customer.getPhonenumber()+")"+"订单信息如下:");
System.out.println("-----------------------------------------");
System.out.println("航班号:"+airline.getNum());
System.out.println("订单号:"+order.getNum());
System.out.println("订单日期:"+order.getDate());
people = Senderpeople;
System.out.println("发件人姓名:"+people.getName());
System.out.println("发件人电话:"+people.getphoneNumber());
System.out.println("发件人地址:"+people.getAdress());
people = recipientpeople;
System.out.println("收件人姓名:"+people.getName());
System.out.println("收件人电话:"+people.getphoneNumber());
System.out.println("收件人地址:"+people.getAdress());
System.out.printf("订单总重量(kg):%.1f\n",allweight);
double allprice = Calculateprice();
System.out.printf("%s%.1f\n",pay.getPay(),allprice);
System.out.printf("\n");
System.out.println("货物明细如下:");
System.out.println("-----------------------------------------");
System.out.println("明细编号\t货物名称\t计费重量\t计费费率\t应交运费");
for (int i =0;i<goods.getNum();i++){
goods.setI(i);
goods.SelectWeight();
System.out.printf("%d\t%s\t%.1f\t%.1f\t%.1f\n",i+1,goods.getName(),goods.getZweight(),goods.getRate(),ordermx.getPrice());
}
}
}
class Airline {
private String num ;
private String date;
private double maxheight;
public String airlinefly;
public String airlineland;
public Airline(){
}
public Airline(String num, String airlinefly,String airlineland,String date, double maxheight) {
this.num = num;
this.date = date;
this.maxheight = maxheight;
this.airlinefly = airlinefly;
this.airlineland = airlineland;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public double getMaxheight() {
return maxheight;
}
public void setMaxheight(double maxheight) {
this.maxheight = maxheight;
}
public String getAirlinefly() {
return airlinefly;
}
public void setAirlinefly(String airlinefly) {
this.airlinefly = airlinefly;
}
public String getAirlineland() {
return airlineland;
}
public void setAirlineland(String airlineland) {
this.airlineland = airlineland;
}
}
class AlPay extends Pay{
@Override
public String getPay(){
return "支付宝支付金额:";
}
}
class Customer {
private String type;
private String num;//客户编号
private String name;//客户姓名
private String phonenumber;//客户电话
private String adress;//客户地址
public Customer(String type ,String num,String name,String phonenumber,String adress) {
this.type = type;
this.num = num;
this.name = name;
this.phonenumber = phonenumber;
this.adress = adress;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
class DGoods extends Goods {
public double getRate() {
double mweight = getZweight();
double rate;
if (mweight >= 100) {
rate = 20.0;
} else if (mweight >= 50) {
rate = 30.0;
} else if (mweight >= 20) {
rate = 50.0;
} else {
rate = 80.0;
}
return rate;
}
}
class EGoods extends Goods{
public double getRate() {
double mweight = getZweight();
double rate;
if (mweight >= 100) {
rate = 30.0;
} else if (mweight >= 50) {
rate = 40.0;
} else if (mweight >= 20) {
rate = 50.0;
} else {
rate = 60.0;
}
return rate;
}
}
abstract class Goods {
private String type;
protected String[] bh = new String[1000];
protected String[] name = new String[1000];
protected double[] width = new double[1000];
protected double[] length = new double[1000];
protected double[] height = new double[1000];
protected double[] weight = new double[1000];
protected double zweight;
protected int num; // 货物数量
protected int i;
public Goods() {
}
public String getName() {
return name[i];
}
public double getWidth() {
return width[i];
}
public double getLength() {
return length[i];
}
public double getHeight() {
return height[i];
}
public double getWeight() {
return weight[i];
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public void setName(String name) {
this.name[i] = name;
}
public void setWidth(double width) {
this.width[i] = width;
}
public void setLength(double length) {
this.length[i] = length;
}
public void setHeight(double height) {
this.height[i] = height;
}
public void setWeight(double weight) {
this.weight[i] = weight;
}
public String[] getBh() {
return bh;
}
public void setBh(String bh) {
this.bh[i] = bh;
}
public double getZweight() {
return zweight;
}
public void setZweight(double zweight) {
this.zweight = zweight;
}
public void SelectWeight() {
double v;
v = getWidth() * getLength() * getHeight() / 6000;
if (v > getWeight()) {
setZweight(v);
} else {
setZweight(getWeight());
}
}
public void setType(String type) {
this.type = type;
}
public abstract double getRate() ;
}
class NGoods extends Goods {
public double getRate() {
double mweight = getZweight();
double rate;
if (mweight >= 100) {
rate = 15.0;
} else if (mweight >= 50) {
rate = 25.0;
} else if (mweight >= 20) {
rate = 30.0;
} else {
rate = 35.0;
}
return rate;
}
}
class Order {
private String num;//订单编号
private String date;//订单日期
public Order(String num, String date) {
this.num = num;
this.date = date;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
class Ordermx {
private double discount;
Goods goods;
Customer customer;
public Ordermx() {
}
public Ordermx(Goods goods, Customer customer){
this.goods = goods;
this.customer = customer;
}
public double getPrice(){
double mweight = goods.getZweight();
double rate = goods.getRate();
double price = mweight * rate;
return price;
}
public void CalculateDiscount(){
String type = customer.getType();
if(type.equals("Individual")){
discount = 0.9;
}
else{
discount = 0.8;
}
}
public double getDiscount(){
return discount;
}
}
abstract class Pay {
public abstract String getPay();
}
abstract class People {
public abstract String getAdress();
public abstract String getName();
public abstract String getphoneNumber();
}
class Recipientpeople extends People {
private String adress;
private String name;
private String phonenumber;
public Recipientpeople(String adress, String name, String phonenumber) {
this.adress = adress;
this.name = name;
this.phonenumber = phonenumber;
}
@Override
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
@Override
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String getphoneNumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
}
class Senderpeople extends People {
private String adress;
private String name;
private String phonenumber;
public Senderpeople(String adress, String name, String phonenumber) {
this.adress = adress;
this.name = name;
this.phonenumber = phonenumber;
}
@Override
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
@Override
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String getphoneNumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
}
class WechatPay extends Pay {
@Override
public String getPay(){
return "微信支付金额:";
}
}
class XianjPay extends Pay{
@Override
public String getPay() {
return "现金支付金额:";
}
}
航空货运管理分析
前面和之前基本相同
增加了判断客户类型来计算费用的折扣和
判断货物类型来确定货物的费率和支付方式的选择
类图分析

类设计分析
相比第一次的类图,多了订单明细的类,并且把货物做成了一个父类,
在其下面多了三个货物类型的子类,Agent类中的功能减少,复杂性降低
代码分析

分析与心得
分析
平均复杂度是 1.40
最大复杂度为 13
分支语句占比较低
心得
平均每个类的方法数适中,类的功能有一定丰富度
相比上一次,虽然进行了迭代,但代码的复杂度却下降,类与类之间的联系更加
合理
踩坑心得
- 在写代码时要仔细,三思而后行。 写代码时一定要详细,所有条件都要考虑清楚,确保提交的时候能一遍过,不然
如果就一个测试点过不了,而你又不知道那个测试点测试的是什么(那就是一件很痛苦的事情了)话不多说,上图

看这这么多部分错误,就知道我内心多么挣扎了和那个答案正确有多么可贵了,所以写的时候一定要仔细,三思而后行,
不然你就只能慢慢摸索了,这会是对你的内心是否强大的考验,也是后面迭代能否完全正确的基础
-
看条件时一定要对号入座。 在第二次迭代时,它例子上给的货物类型的顺序和给的文件中的货物类型对应的1.
费率不一样,导致后面提交时出现答案错误,还好后面很快就找出来了,不然估计又会困扰我好久,所以条件一定要看
仔细,务必让其一一对应,否则你计算的逻辑都出问题了,怎么可能做对呢?这也体现出了自己设置用例的重要性,光靠
老师的样例不鞥每次都能刚好解决问题,学会自己设置样例进行调试很重要。 -
要理解题目里的意思,多和同学交流一下自己的看法。在第一次作业时,在比较航班载重量时出现理解错误,我以为
题目中的重量是实际重量,后面和同学交流后才发现是计费重量,所以不要以为你以为的就是真的,遇到问题要多交流,不是
你以为的就是你以为,这点很重要
改进建议
- 第一设计时就应该考虑清楚订单明细这个类,不要等第二次迭代才反应过来要加进去,这会大大增加你第二次迭代的难度。
类设计的设计要合理,像第一次设计的Agent类承担的功能就太多了,要进行合理的修改
2.方法的功能要更明确一点,不要因为单纯的完成题目而增加或减少方法的功能,使其符合单一职责原则,相比与上一次有了
点进步
总结
-
在这一次的迭代联系中,使我对类与类之间的关系有了更深的了解,
对面向对象的原则的运用更加灵活,对理论和实际的情况要进行联系,
就比如说这次是货运,就要联系实际中的货运情况,并要拥抱变化,
不要害怕变化。 -
在写代码时一定要仔细,尽可能一遍过,(不然就会发生很痛苦的事情),
这次的作业是如此,后面的题目也是如此,一定要仔细,能为后面解决很多问题。
最后通过这次作业,我的编程能力等到了提高,类设计的注意点更加的了解,对继承的
使用更加熟练,面向对象的原则运用更加灵活,为下一次的迭代打好了更加坚实的基础

浙公网安备 33010602011771号