Adding print option to UI

This commit is contained in:
2020-06-01 16:32:03 -05:00
parent db07554c4c
commit e21c430d42

View File

@@ -83,6 +83,7 @@ public class AlgorithmTester{
boolean bubble=false, selection=false, insertion=false; boolean bubble=false, selection=false, insertion=false;
boolean quick=false, counting=false; //radix=false, merge=false; boolean quick=false, counting=false; //radix=false, merge=false;
boolean ready=false; boolean ready=false;
boolean print = false;
System.out.print("Please enter file name: "); System.out.print("Please enter file name: ");
filename = sc.next(); filename = sc.next();
while(!ready){ while(!ready){
@@ -123,6 +124,19 @@ public class AlgorithmTester{
System.out.println("Invalid input"); System.out.println("Invalid input");
} }
} }
try{
System.out.println("Print sorted list?");
System.out.println("1) Yes");
System.out.println("2) No");
input = sc.nextInt();
switch(input){
case 1 -> print=true;
case 2 -> print=false;
default -> System.out.println("Invalid input, defaulting to no");
}
}catch(InputMismatchException ex){
System.out.println("Invalid input, defaulting to no");
}
ArrayList<SortResult> results = new ArrayList<SortResult>(); ArrayList<SortResult> results = new ArrayList<SortResult>();
if(bubble){ if(bubble){
BubbleSorter bubSorter = new BubbleSorter(filename); BubbleSorter bubSorter = new BubbleSorter(filename);
@@ -145,9 +159,11 @@ public class AlgorithmTester{
results.add(qSorter.measuredSort()); results.add(qSorter.measuredSort());
} }
for(SortResult e: results){ for(SortResult e: results){
if(print){
for(int i: e.getSortedArray()){ for(int i: e.getSortedArray()){
System.out.print(i+" "); System.out.print(i+" ");
} }
}
System.out.println(""); System.out.println("");
System.out.println(e.getSortType()+" sort took:"); System.out.println(e.getSortType()+" sort took:");
System.out.println(e.getComparisonsUsed()+" comparisons"); System.out.println(e.getComparisonsUsed()+" comparisons");