Class InputData

java.lang.Object
  extended by InputData

public class InputData
extends java.lang.Object

A general helper class that reads data form keyboard or files...


Field Summary
private static java.lang.String checkDigits
           
static int numberOfLines
          The maximum number of lines in a text file that is read into an array when reading the file.
 
Constructor Summary
InputData()
           
 
Method Summary
static double[] convertStrToDble(java.lang.String[] s)
          Converts a String[] with double or int values to a double[].
static double[] dataStats(java.lang.String s)
          Takes filename s with file that has int or doubles and returns sum, mean, SD, min, max in a double[] of size 5 in this order.
static void deleteDoubleFiles(java.lang.String extracted, java.lang.String rar, java.lang.String resultTxtFile)
          If a RAR was extracted, this prepares the WIndows DOS cmd command to delete the original RAR files.
static java.lang.String[] getData(java.lang.String ss)
          Requests to get input data from a file or keyboard, than returns it in a String[], where everything was split by spaces.
static java.lang.String ISBN10to13(java.lang.String ISBN)
          Convert ISBN-10 to ISBN-13
static java.lang.String ISBN13to10(java.lang.String ISBN)
          Convert ISBN-13 to ISBN-10
static java.lang.String[] keyboardEntry()
          Reads data from keyboard.
static java.lang.String[] readFile(java.lang.String fileName)
          Reads data from file.
static java.lang.String removeSpace(java.lang.String s)
           
private static java.lang.String[] split(java.lang.String[] st, int i)
          Splits an array of strings into smaller strings by spaces.
static double[] stat(double[] db)
          Calculates sum, mean, SD, min, max.
static void writeFile(java.lang.String[] s, java.lang.String filenme, boolean append)
          Writes a String[] to file, each index is a new line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

checkDigits

private static java.lang.String checkDigits

numberOfLines

public static final int numberOfLines
The maximum number of lines in a text file that is read into an array when reading the file. i.e. When provided with a text file it will only read the first numberOfLines and ignore the rest. It's limited due to the hard-coding of this value variable when creating arrays.

See Also:
Constant Field Values
Constructor Detail

InputData

public InputData()
Method Detail

dataStats

public static double[] dataStats(java.lang.String s)
Takes filename s with file that has int or doubles and returns sum, mean, SD, min, max in a double[] of size 5 in this order.


getData

public static java.lang.String[] getData(java.lang.String ss)
Requests to get input data from a file or keyboard, than returns it in a String[], where everything was split by spaces.


keyboardEntry

public static java.lang.String[] keyboardEntry()
                                        throws java.io.IOException
Reads data from keyboard. Capacity of 50,000 lines To end data entry, hit return twice.

Throws:
java.io.IOException

readFile

public static java.lang.String[] readFile(java.lang.String fileName)
                                   throws java.io.IOException,
                                          java.io.FileNotFoundException
Reads data from file. Capacity - numberOfLines lines.

Returns:
a String[] where each line is in a different index. The length of String[] is the exact number of lines used in creating String[]. There no unused [i]
Throws:
java.io.IOException
java.io.FileNotFoundException

writeFile

public static void writeFile(java.lang.String[] s,
                             java.lang.String filenme,
                             boolean append)
Writes a String[] to file, each index is a new line. Skips null lines.

Parameters:
s - The String[] to write to the file
filenme - The name and full path of the output text file.
append - true if you wish to append the array to the end of the text file, false to replace and create a new text file.

split

private static java.lang.String[] split(java.lang.String[] st,
                                        int i)
Splits an array of strings into smaller strings by spaces. Adds up all strings to a new array.

Parameters:
st - The original String[]
i - - number of indexes filled, should be the min if unknown. It doesn't remove extra empty lines
Returns:
A String[] composed of the strings split by spaces.

removeSpace

public static java.lang.String removeSpace(java.lang.String s)

convertStrToDble

public static double[] convertStrToDble(java.lang.String[] s)
Converts a String[] with double or int values to a double[].


stat

public static double[] stat(double[] db)
Calculates sum, mean, SD, min, max. of a double[] into a double[5] in this order.

Parameters:
db - a double array with double values
Returns:
[0] = sum, [1] = mean, [2] = sD, [3] = min, [4] = max.

ISBN13to10

public static java.lang.String ISBN13to10(java.lang.String ISBN)
                                   throws java.lang.NumberFormatException
Convert ISBN-13 to ISBN-10

Parameters:
ISBN - an ISBN-13
Returns:
an ISBN-10
Throws:
java.lang.NumberFormatException

ISBN10to13

public static java.lang.String ISBN10to13(java.lang.String ISBN)
                                   throws java.lang.NumberFormatException
Convert ISBN-10 to ISBN-13

Parameters:
ISBN - an ISBN-10
Returns:
an ISBN-13
Throws:
java.lang.NumberFormatException

deleteDoubleFiles

public static void deleteDoubleFiles(java.lang.String extracted,
                                     java.lang.String rar,
                                     java.lang.String resultTxtFile)
If a RAR was extracted, this prepares the WIndows DOS cmd command to delete the original RAR files.