//File: sort.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri //the sort command was not documented as a requirement in any of the //specifications, however, we have implemented a version of it in this file //sort accepts two option flags (-a) for ascending order and (-d) for descending order //it is intended to be applied to strings import java.util.*; public class sort extends VMachine { public sort() { } public void run() { try { //if there are no option flags, then the default is ascending order //or if the flag is (-a) if(args.length == 0 || (args.length > 0 && args[0].toLowerCase().compareTo("-a")==0)) { //then create a new vector used to store the strings Vector strvector = new Vector(2,2); //take input String str = sysapi.Read(IN); //while there is still input while(str.compareTo("") != 0) { //add the input to the vector strvector.add(str); //wait for more input str = sysapi.Read(IN); } //convert input to an array Object[] strarray = strvector.toArray(); //sort the array Arrays.sort(strarray); //write the array to the desired output for(int i =0;i 0 && args[0].toLowerCase().compareTo("-d")==0) { Vector strvector = new Vector(2,2); String str = sysapi.Read(IN); while(str.compareTo("") != 0) { strvector.add(str); str = sysapi.Read(IN); } Object[] strarray = strvector.toArray(); //sort the array in descending order Arrays.sort(strarray,Collections.reverseOrder()); for(int i = 0; i < strarray.length; i++) { sysapi.Write(OUT,strarray[i] + "\n"); } } } catch(Exception ex) { System.out.println(ex); } sysapi.Exit(vmh,owner); } }