java - 编写代码以确定航班的总成本
问题描述
总成本可以通过将去程航班和回程航班的成本相加来计算。然而,离开飞行和返回飞行都是飞行类的对象。有没有办法将这些添加到值中以获得总成本?
这是我尝试过的:
public Double getTotalCost() {
return departingFlight + returningFlight;
}//End of method
飞行类:公共类飞行{
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
}//课程结束
任何帮助将不胜感激。:)
解决方案
这是你需要做的。将两个航班添加到参数,然后:
public Double getTotalCost(Flight a,Flight b) {
return a.getCost() + b.getCost();
}//End of method
推荐阅读
- python-3.x - 电话簿不能存储 2 个同姓的人
- typescript - 使用 Express/Angular 为投资组合网站缓存图像的最佳方法
- pyspark - 在 pyspark 中调用函数,将数据帧中的值作为字符串
- api - 无法使快速路由参数起作用
- c - 是否有检测 C 程序中的内存错误的解决方案?
- c# - 为什么 HttpHeaders.GetValues() 这么慢?
- csv - GOCSV 映射到带有日期/时间的结构:字段为空时的问题
- python - 将数字列表传递给 Python 脚本
- spring - Spring Boot Test 如何跨多个测试套件保持上下文?
- c++ - C++ 输出的就地计数器