時計というクラスがあります。かかった時間を計算します。私のプロジェクトでは、コンストラクターを使用して開始時間を初期化する必要があります。コンストラクターを使用すると、常に時間 = 0.0 ms になります。誰かがこれを整理するのを手伝ってくれますか?
時計.java
public class Clock {
private long start;
public Clock() {
start = 0;
}
public Clock(String s) {
start = s;
}
public void start() {
start = System.currentTimeMillis();
}
public double stop() {
long stop = System.currentTimeMillis();
double time = stop - start;
return time;
}
}
別のクラスで呼び出しているコードの一部。c はクラス Clock.java からインスタンス化されたオブジェクトです
public static void insertion(Clock c, Sort s, Scanner sc) throws IOException {
for (int count = 0; count < 11; count++) {
String path[] = selectPath(count);
String filepath = path[0];
int num = Integer.parseInt(path[1]);
int[] NumArrays = populate(filepath, num);
c.start();
s.insertionSort(NumArrays);
double timeI = c.stop();
System.out.println("Insertion sort took " + timeI + "ms for " + path[1] + " data");
}
menu(sc, c, s);
}