Originally posted by Kirill NKaufmann:
I have made sort of a pseudocode for the project
is that more or less correct in terms of the conversion steps such as wrappers etc?
1) Create a Vector
2) Bring up on screen instructions (to enter a value)
3) Convert the input String to an integer object
4) After the value is entered ask t he user whether he or she wants to enter another value or to sort the numbers. If the user chooses to input another value go to step 2. If the user chooses to sort the values proceed to step 6.
5) Append the integer object into the Vector
6) Detect if only 1 or no values have been entered and give an error message and go to step 2. Else go to step 7
7) Use a loop to compare the elements in the Vector and sort them appropriately.
Thanks
Kaufmann
Kirill,
In line with keeping the program simple, I suggest prompting the user to input how many integers they would like stored in the vector/array.
Then utilize the 'for' loop to place the user's input in to the vector/array. After the input "string(s)" is/are converted to integer format, you can then sort the integers within the vector in ascending order. I am not sure, however, how you want to compare the data or manipulate it in any other way.
I have made a program that does this and then displays the data contained within the vector on the screen for the user to see. Please let me know if posting this code may help you to get some ideas. I would be happy to do so.
Within my code, I used a class called SimpleIO, written by K.N. King. This class helps you to read a user's keyboard input. This class came with the book for a Java course that I am taking, and looks like this:
//////////////////////////////////////////////////////////////
// From JAVA PROGRAMMING: FROM THE BEGINNING, by K. N. King //
// Copyright (c) 2000 W. W. Norton & Company, Inc. //
// All rights reserved. //
// This program may be freely distributed for class use, //
// provided that this copyright notice is retained. //
// //
// SimpleIO.java (Appendix E, page 763) //
//////////////////////////////////////////////////////////////
// Provides prompt and readLine methods for console input
import java.io.*;
public class SimpleIO {
private static InputStreamReader streamIn =
new InputStreamReader(System.in);
private static BufferedReader in =
new BufferedReader(streamIn, 1);
// Displays the string s without terminating the current
// line
public static void prompt(String s) {
System.out.print(s);
System.out.flush();
}
// Reads and returns a single line of input entered by the
// user; terminates the program if an exception is thrown
public static String readLine() {
String line = null;
try {
line = in.readLine();
} catch (IOException e) {
System.out.println("Error in SimpleIO.readLine: " +
e.getMessage());
System.exit(-1);
}
return line;
}
}
Hope this helps Kirill.