error catching
This commit is contained in:
@@ -21,6 +21,7 @@ public class AlgorithmTester{
|
||||
System.out.println("Please select an option:");
|
||||
System.out.println("1) Make a file of random numbers");
|
||||
System.out.println("2) Sort a file of random numbers");
|
||||
System.out.println("3) Sort a file of words");
|
||||
System.out.println("0) Exit");
|
||||
try{
|
||||
input = sc.nextInt();
|
||||
@@ -29,6 +30,7 @@ public class AlgorithmTester{
|
||||
switch(input){
|
||||
case 1 -> makeFile();
|
||||
case 2 -> sortFile();
|
||||
case 3 -> sortWordFile();
|
||||
case 0 -> quit=true;
|
||||
default -> System.out.println("Invalid input");
|
||||
}
|
||||
@@ -88,6 +90,7 @@ public class AlgorithmTester{
|
||||
boolean[] sortingAlgoChoices = new boolean[sortingAlgoNames.length];
|
||||
System.out.print("\nPlease enter file name: ");
|
||||
filename = sc.next();
|
||||
RandomNumberFileReader reader = new RandomNumberFileReader(filename);
|
||||
while(!ready){
|
||||
try{
|
||||
System.out.println("\nEnter the number of an algorithm you wish to use.");
|
||||
@@ -139,7 +142,6 @@ public class AlgorithmTester{
|
||||
boolean quickTWP=sortingAlgoChoices[6];
|
||||
boolean merge=sortingAlgoChoices[7];
|
||||
ArrayList<SortResult> results = new ArrayList<SortResult>();
|
||||
RandomNumberFileReader reader = new RandomNumberFileReader(filename);
|
||||
if(bubble){
|
||||
BubbleSorter bubSorter = new BubbleSorter(reader);
|
||||
results.add(bubSorter.measuredSort());
|
||||
@@ -173,17 +175,23 @@ public class AlgorithmTester{
|
||||
results.add(mSorter.measuredSort());
|
||||
}
|
||||
for(SortResult e: results){
|
||||
if(print){
|
||||
for(int i: e.getSortedArray()){
|
||||
System.out.print(i+" ");
|
||||
if(e!=null){
|
||||
if(print){
|
||||
for(int i: e.getSortedArray()){
|
||||
System.out.print(i+" ");
|
||||
}
|
||||
System.out.print("\n");
|
||||
}
|
||||
System.out.print("\n");
|
||||
System.out.println("\n"+e.getSortType()+" of "+e.getSortCount()+" numbers with range "+e.getMin()+" to "+e.getMax()+" took:");
|
||||
System.out.println(e.getComparisonsUsed()+" comparisons");
|
||||
System.out.println(e.getWritesUsed()+" write operations");
|
||||
System.out.println(e.getTimeUsed()+" milliseconds");
|
||||
}
|
||||
System.out.println("\n"+e.getSortType()+" of "+e.getSortCount()+" numbers with range "+e.getMin()+" to "+e.getMax()+" took:");
|
||||
System.out.println(e.getComparisonsUsed()+" comparisons");
|
||||
System.out.println(e.getWritesUsed()+" write operations");
|
||||
System.out.println(e.getTimeUsed()+" milliseconds");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void sortWordFile(){
|
||||
//String filename;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user