41 lines
1.4 KiB
Java
41 lines
1.4 KiB
Java
package Sorting;
|
|
|
|
import java.util.Scanner;
|
|
import java.util.InputMismatchException;
|
|
/**
|
|
* 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
|
|
* of random numbers, and to select a set of algorithms to test on a file of random
|
|
* numbers.
|
|
*/
|
|
public class AlgorithmTester{
|
|
|
|
final static Scanner sc = new Scanner(System.in);
|
|
static int input;
|
|
public static void main(String[] args) {
|
|
System.out.println("SORTING ALGORITHM TESTER\n");
|
|
boolean quit = false;
|
|
while(!quit){
|
|
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")
|
|
|
|
try{
|
|
input = sc.nextInt();
|
|
//Using the new switch syntax introduced in JDK 13
|
|
//this is a switch expression (lambda expression) rather than a switch statement
|
|
switch(input){
|
|
case 1 -> makeFile();
|
|
case 2 -> sortFile();
|
|
case 3 -> quit=true;
|
|
}
|
|
|
|
} catch(InputMismatchException ex){
|
|
System.out.println("Invalid input");
|
|
}
|
|
}
|
|
sc.close();
|
|
}
|
|
|
|
} |