简体   繁体   English

编写代码以确定航班的总成本

[英]Write code to determine the total cost of a flight

The total cost can be calculated by adding the cost of departingFlight and returningflight.总成本可以通过将去程航班和回程航班的成本相加来计算。 However, departingFlight and returningFlight are both objects from the class Flight.但是,离开航班和返回航班都是来自 class 航班的对象。 Is there a way to add these to values to get the total cost?有没有办法将这些添加到值中以获得总成本?

This is what I tried:这是我尝试过的:

public Double getTotalCost() {
    return departingFlight + returningFlight;
}//End of method

Flight class: public class Flight {航班 class:公共 class 航班 {

private String code;
private String origin;
private String destination;
private String departureTime;
private String arrivalTime;
private Double cost;

public Flight(String cde, String orig , String dest, String dtime,String atime,Double cst) {
    code = cde;
    origin = orig;
    destination = dest;
    departureTime = dtime;
    arrivalTime = atime;
    cost = cst;

}//End of constructor flight

public String getCode() {
    return code;

}//End of method

public String getDepartureTime() {
    return departureTime;
}//End of method

public Double getCost() {
    return cost;
}//End of method

public String toString() {
    return "" + cost + "\t " + origin + " " + departureTime + "\t" + destination + " " + arrivalTime; 
    }//end of toString method

}//End of class }//class结束

Any help would be greatly appreciated.任何帮助将不胜感激。 :) :)

this is what you need to do.这是你需要做的。 add two flights to arguments and then:将两个航班添加到 arguments 然后:

public Double getTotalCost(Flight a,Flight b) {
    return a.getCost() + b.getCost();
}//End of method

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM