much implementation, ready for first test

This commit is contained in:
2020-05-30 18:46:10 -05:00
parent 741d29f148
commit c680ec7671
8 changed files with 159 additions and 11 deletions

View File

@@ -1,7 +1,9 @@
package Sorting;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.InputMismatchException;
//import java.time.temporal.ChronoUnit;
/**
* This class contains the main method and presents an interface for the user to
* compare sorting algorithm efficiencies. The user will be able to generate files
@@ -19,7 +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("0) Exit")
System.out.println("0) Exit");
try{
input = sc.nextInt();
//Using the new switch syntax introduced in JDK 13
@@ -78,12 +80,14 @@ public class AlgorithmTester{
private static void sortFile(){
String filename;
int input;
boolean bubble, selection, insertion, quick, counting, radix, merge, ready;
boolean bubble=false, selection=false, insertion=false;
boolean quick=false, counting=false; //radix=false, merge=false;
boolean ready=false;
System.out.print("Please enter file name: ");
filename = sc.nextLine();
while(!ready){
try{
System.out.println("Enter the number of the algorithms you wish to use.")
System.out.println("Enter the number of the algorithms you wish to use.");
System.out.println("Enter 0 to start sorting.");
if(bubble){
System.out.print("*");
@@ -115,11 +119,36 @@ public class AlgorithmTester{
case 0 -> ready=true;
default -> System.out.println("Invalid input");
}
} catch(InputMismatchException ex){
System.out.println("Invalid input");
}
ArrayList<SortResult> results = new ArrayList<SortResult>();
if(bubble){
var bubSorter = new BubbleSorter(filename);
results.add(bubSorter.measuredSort());
}
if(selection){
var selSorter = new SelectionSorter(filename);
results.add(selSorter.measuredSort());
}
if(insertion){
var inSorter = new InsertionSorter(filename);
results.add(inSorter.measuredSort());
}
if(counting){
var countSorter = new CountingSorter(filename);
results.add(countSorter.measuredSort());
}
if(quick){
var qSorter = new QuickSorter(filename);
results.add(qSorter.measuredSort());
}
for(SortResult e: results){
System.out.println(e.getSortType()+" sort took:");
System.out.println(e.getComparisonsUsed()+" comparisons");
System.out.println(e.getSwapsUsed()+" swaps");
System.out.println(e.getTimeUsed().toMillis()+" milliseconds\n");
}
}
}
}