I have made a program where I'm trying to make a 'sorting shell' using eclipse. Some basic functions I can do are load which sorting algorithm to use, unload it, sort using the algorithm and unload the algorithm from the shell using a specific ID.
I have separate classes for all the sorting algorithms (Bubble, Insertion, Quick, etc), but I don't know how to load them into the shell. This is what I have so far:
public static void main(String[] args) {
boolean exit_loop = true;
while (exit_loop){
String[] command;
command = input();
switch(command[0]){
case "load":
// ???
}
break;
case "tag":
break;
case "sort":
break;
case "unload":
break;
case "quit":
exit_loop = false;
break;
default:
System.out.println("Input a valid command!");
break;
}
}
}
public static String[] input(){
Scanner user_input = new Scanner( System.in );
String command;
System.out.print("sort:>");
command = user_input.next();
String[] first = command.split("\\s+");
return first;
}
So even if I'm able to get the user-input, I'm not sure how to actually load my sorting algorithm classes, (which I have implemented as separate classes).
Here is an example of how I've implemented one of my sorting algorithms:
class Bubble implements SortingAlgorithms{
public int[] sort(int[] array){
int temp;
boolean swap = true;
while(swap){
swap = false;
for (int i=0; i < array.length-1; i++){
if (array[i] > array[i + 1]){
temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
swap = true;
}
}
}
return array;
}
private String id;
public String name() {
return id;
}
public void name(String name) {
id = name;
}
Any help would be much appreciated!