formatting time output
This commit is contained in:
@@ -169,7 +169,7 @@ public class AlgorithmTester{
|
||||
System.out.println("\n"+e.getSortType()+" sort took:");
|
||||
System.out.println(e.getComparisonsUsed()+" comparisons");
|
||||
System.out.println(e.getWritesUsed()+" write operations");
|
||||
System.out.println(e.getTimeUsed().toMillis()+" milliseconds");
|
||||
System.out.println(e.getTimeUsed()+" milliseconds");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package Sorting;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Locale;
|
||||
import java.text.NumberFormat;
|
||||
/**
|
||||
* This is a class to hold the efficiencty results of a sorter. We will use this
|
||||
* because we can only have one return value from a method, but want to get more
|
||||
@@ -23,25 +25,27 @@ public class SortResult {
|
||||
private Integer [] sortedArray;
|
||||
private String comparisonsUsed;
|
||||
private String writesUsed;
|
||||
private Duration timeUsed;
|
||||
private String timeUsed;
|
||||
|
||||
public SortResult(String st, Integer[] a, long c, long w, Duration t){
|
||||
sortType = st;
|
||||
sortedArray = a;
|
||||
NumberFormat nf = NumberFormat.getInstance(Locale.US);
|
||||
if(c==0){
|
||||
comparisonsUsed = "No";
|
||||
}
|
||||
else{
|
||||
comparisonsUsed = Long.toString(c);
|
||||
comparisonsUsed = nf.format(c);
|
||||
}
|
||||
writesUsed = Long.toString(w)
|
||||
timeUsed = t;
|
||||
writesUsed = nf.format(w);
|
||||
timeUsed = nf.format(t.toMillis());
|
||||
}
|
||||
|
||||
public SortResult(String st, Integer[] a, Duration t){
|
||||
sortType = st;
|
||||
sortedArray = a;
|
||||
timeUsed = t;
|
||||
NumberFormat nf = NumberFormat.getInstance(Locale.US);
|
||||
timeUsed = nf.format(t.toMillis());
|
||||
comparisonsUsed = "Unknown";
|
||||
writesUsed = "Unknown";
|
||||
}
|
||||
@@ -54,7 +58,7 @@ public class SortResult {
|
||||
return sortedArray;
|
||||
}
|
||||
|
||||
public Duration getTimeUsed(){
|
||||
public String getTimeUsed(){
|
||||
return timeUsed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user