Class 最终比率将不计算在内。我的类方法被称为错误的吗?
在我的代码中,我必须计算航班延误的次数/航班总数。我已经写了代码,除了最后的打印输出,其他一切都正常。有人看到问题了吗Class 最终比率将不计算在内。我的类方法被称为错误的吗?,class,variables,object,methods,Class,Variables,Object,Methods,在我的代码中,我必须计算航班延误的次数/航班总数。我已经写了代码,除了最后的打印输出,其他一切都正常。有人看到问题了吗 import au.com.bytecode.opencsv.CSVReader; // javac -classpath .;opencsv-2.3.jar flightinfo.java import java.util.*; import java.io.*; import java.lang.*; public class flightinfo2{ public
import au.com.bytecode.opencsv.CSVReader;
// javac -classpath .;opencsv-2.3.jar flightinfo.java
import java.util.*;
import java.io.*;
import java.lang.*;
public class flightinfo2{
public static void main (String [] args) throws Exception{
CSVReader reader = new CSVReader(new FileReader("delayed.csv"));
String [] nextLine;
Map<String, Carrier> airlines = new HashMap<String, Carrier>();
while ((nextLine = reader.readNext()) != null) {
// At this point, nextLine is the name of the carrier, e.g., "Continental"
// nextLine can be used as the key in your "airlines" map. E.g., airlines.put(nextLine, new Carrier());
if (airlines.containsKey(nextLine[1])){
airlines.get(nextLine[1]).addNumFlights(Integer.valueOf(nextLine[6]));
airlines.get(nextLine[1]).addNumDelayed(Integer.valueOf(nextLine[7]));
airlines.get(nextLine[1]).setDelayedRatio();
}
else {
airlines.put(nextLine[1], new Carrier());
airlines.get(nextLine[1]).setName(nextLine[1]);
airlines.get(nextLine[1]).setNumFlights(Integer.valueOf(nextLine[6]));
airlines.get(nextLine[1]).setNumDelayed(Integer.valueOf(nextLine[7]));
}
}
airlines.get("Continental").print();
airlines.get("Atlantic Southeast").print();
airlines.get("American Eagle").print();
airlines.get("Delta").print();
airlines.get("ExpressJet").print();
airlines.get("United").print();
airlines.get("SkyWest").print();
airlines.get("US Airways").print();
airlines.get("JetBlue").print();
airlines.get("American").print();
airlines.get("Mesa").print();
airlines.get("Frontier").print();
airlines.get("AirTran").print();
airlines.get("Southwest").print();
}
}
}
打印输出如下所示:
大陆航空:92,81,0而不是:
totalDelayedRatio = (delayedFlights/totalFlights);
尝试显式使用“this”:
this.totalDelatedRatio = (delayedFlights/totalFlights);
顺便说一句,我把这个方法编辑成了我原来的方法——作为一个空白。但是,this.totalDelayedRatio没有更新变量
this.totalDelatedRatio = (delayedFlights/totalFlights);