I have the following code below. The input is from a text file called test.txt. INPUT: @0001 Variable1 3. @0004 variable2 $4. @0008 Variable3 mmddyy10. @0015 Variable4 4.
Column1 Value of Current + Column3 Value of Previous gives you the next row's Column1 Value, and this must continue as each value can be updated within the vector.
I need to manipulate the output such that: The value of each subsequent gives you the next.(Looking at the input will make more sense). Each value in the vector is stored in a String. I am able to take the values out of the String, but unable to manipulate to get the next. This source code is able to add a value to the vector, but unable to update it.
public footest() { readFile(); writeObject(); findAdd(); CalculateCols(); writeFile(); }
public void readFile() { System.out.println(""); System.out.println(">> Loading data from file into vector"); try { StringTokenizer words; String line; String word;
// prepare file for input BufferedReader objIn = new BufferedReader(new BufferedReader(new FileReader("test.txt")));
System.out.println("The input is : ");
// prepare to extract words from a line // process lines until 'null' (no more input) while ( (line = objIn.readLine()) != null) { //tokenizing line StringTokenizer st = new StringTokenizer(line);
//Initiate size and name of input. currColSize = (int)Double.parseDouble(st.nextToken().substring(1)); varName = st.nextToken(); currVarSize = st.nextToken();
//Add each value to a vector as a String String fooValue = Integer.toString(currColSize); lineData.add(fooValue); lineData.add(varName); l ineData.add(currVarSize);
//Conversion to integer values of each Variable Size int temp; //If Character if (currVarSize.startsWith("$")) { temp = (int)Double.parseDouble(currVarSize.substring(1)); } //If DateW (W is any integer) else if (currVarSize.startsWith("mmddyy")) { temp = (int)Double.parseDouble(currVarSize.substring(6)); } //If Integer else { temp = (int)Double.parseDouble (currVarSize); } nextColSize = currColSize + temp; currColSize = nextColSize; System.out.println("@" +currColSize +" " +varName +" " +currVarSize);
public void CalculateCols() { //Conversion to integer values of each Variable Size int temp; //If Character if (currVarSize.startsWith("$")) { temp = (int)Double.parseDouble(currVarSize.substring(1)); } //If DateW (W is any integer) else if (currVarSize.startsWith("mmddyy")) { temp = (int)Double.parseDouble(currVarSize.substring(6)); } //If Integer else { temp = (int)Double.parseDouble (currVarSize); } System.out.println("@" +currColSize +" " +varName +" " +currVarSize);
// nextColSize = currColSize + temp; // currColSize = nextColSize; writeObject(); System.out.println("The next Column size should be : @" +currColSize); }
public void writeFile() { System.out.println(""); System.out.println(">> Writing to File");
try { BufferedWriter bw = new BufferedWriter(new FileWriter("data.txt")); for(int i = 3; i < lineData.size(); i = i+3) { bw.write("@" +lineData.elementAt(i) +" " +lineData.elementAt(i+1) +" " +lineData.elementAt(i+2)); bw.newLine(); } bw.close(); System.out.println("DATA EDITING COMPLETE!!"); } catch (IOException f) { System.out.println(">> Error while accessing "+ "data.txt"); } }
public static void main(String[] args) { footest Junaid = new footest(); }