Re: Help with java insertion sort program
On 08/10/2014 12:30 AM, Jeff Higgins wrote:
On 08/10/2014 12:11 AM, Scott Dunning wrote:
Ok so I realized that I was not filling the array with anything but now
I'm having issues filling it correctly. It's only filling the array
with three of the user inputs and I just cannot figure out why....
I thought you had that sorted over at stackoverflow.
I must have misread that too.
Please, PLEASE, use java.io.Console class. It makes joy.
If your Professor disallows it, understand him as saying:
"F**k me runnin'."
Huh, some Java IDEs understand Console the same way!
School begins Monday for our local grade-schoolers,
are you sure you're in a summer class?
import javax.swing.JOptionPane;
public class DriverSort {
public static void main(String[] args) {
Object[] sorts = {"Insertion", "Selection", "Bubble"};
String sortString = (String)JOptionPane.showInputDialog(
null,
"Select a sort algorithm\nCancel quits the program",
"Sort Algorithm Selector",
JOptionPane.PLAIN_MESSAGE,
null,sorts,"Insertion");
if(sortString == null) {
System.exit(1);
} else if(sortString != "Insertion"){
JOptionPane.showMessageDialog(
null, "Selection and Bubble sorts are not implemented");
System.exit(2);
}
String arrayString = (String)JOptionPane.showInputDialog(
null,
"Enter a space separated list of integers\nCancel quits the
program",
"The Array to Sort"
,JOptionPane.PLAIN_MESSAGE,null,null,"");
if(arrayString == null) {
System.exit(3);
}
try {
String[] stringArray = arrayString.split(" ");
int[] input = new int[stringArray.length];
for (int i = 0; i < stringArray.length; i++) {
input[i] = Integer.parseInt(stringArray[i]);
}
Sorter.insertionSort(input);
Sorter.printArray(input);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(
null, "Could not parse a list of integers");
System.exit(4);
}
}
}