import java.io.*; // Import good I/O functions import java.net.*; // Import network functions public class ffio { // Create class ffio public int gettotalweeks(int team) throws IOException { URL data = new URL("http://webpages.charter.net/rrblock/data"+team+".dat"); int total=0; String exclaims = "\n, "; char[] exclaim; exclaim=exclaims.toCharArray(); int newlinecounter=0; int commacounter=0; StringBuffer datafile = new StringBuffer(onlineinput(data, -1, 0).toString()); int state=0; int gather=1; for(int i=0; i < datafile.length(); i++) { if(datafile.charAt(i) == exclaim[0]) { newlinecounter++; if(newlinecounter==3) { state=1; } } if(newlinecounter >= 3) { if(state==1) { if(datafile.charAt(i) == exclaim[1]) { commacounter++; } if(commacounter==2) { state=2; } } if(state==2) { if((datafile.charAt(i) == exclaim[1]) && (gather == 1)) { total++; } if(datafile.charAt(i) == exclaim[0]) { state=1; gather=0; } } } } return total; } public String getplayerdata(int teamid, int playerposition, int position, int week) throws IOException { // Create function getplayerdata System.out.println("Checking for data for Team" + teamid + " and player " + playerposition + " in position " + position + " for week " + week + "."); // Update me on what data we are looking up URL datasrc = new URL("http://webpages.charter.net/rrblock/data"+teamid+".dat"); // Create a URL object pointing to the datafile int newlinecounter=0; // Create a new line counter to keep track of newline carriers // int playeridcounter=0; // Create playeridcounter NOT USED int commacounter=0; // Create a comma counter // int idcounter=0; // Create idcounter NOT USED int state=0; // Set the state of the data gathering loop StringBuffer datafile = new StringBuffer(onlineinput(datasrc, -1, 0).toString()); // Create the datafile string buffer which contains all the data in the datafile referenced by the URL above // int[] playerid = new int[14]; // Create playerid NOT USED String exclaims = "\n, "; // Create a string of important characters char[] exclaim; // Create a character array to hold the string exclaim=exclaims.toCharArray();// Conver the string to the character array StringBuffer playerdata = new StringBuffer(); // Create a new string buffer to hold the data we collect int testfornull=0; // A temporary variable to test for a useless comma ie. 0,,0 where the second comma would be useless as it seperates no data // UPDATE: ATP the program should have collected the data from the data file and stored it in datafile as well as created numerous variables for use in the next loop for(int i = 0; i < datafile.length(); i++) { // Start the monster and begin collecting data until there is no more parsing all the while // System.out.println("State " + state + "Char" + datafile.charAt(i) + "newline" + newlinecounter + "commacounter" + commacounter); if(datafile.charAt(i) == exclaim[0]) { // Check for a new line newlinecounter++; // If we find one add one to the counter if(newlinecounter==3){ // If newlinecounter = 3 then we have passed the introduction part and are ready to collect the data state=1; // Tell the loop we are at the beginning of the important stuff } } if(newlinecounter >= 3) { // If we are in the main content of the data file continue if(state==1) { // If the state is 1 and not 2 (these are all it can be if newlinecount >= 3 if(datafile.charAt(i) == exclaim[1]) { // If the character is a comma commacounter++;// Increase the counter } if(commacounter==2) { // If the counter = 2 state=2; // Change the state to 2 as we are in the player data section of the file and start collecting data } } if(state==2) { // If we are ready to extract data // System.out.println("State=2 " + datafile.charAt(i)); if((datafile.charAt(i) != exclaim[1]) && (datafile.charAt(i) != exclaim[2])) { // If it isn't a comma and it isnt a space then it must be data! if(commacounter==(2+week)) { // If we are in the right column // if(playerid[playeridcounter]==pplayerid) { testfornull=0; // We have found data so any comma before or after means something playerdata.append(datafile.charAt(i)); // Apend the data // System.out.println("State=1 " + playerdata); // } } // if(commacounter==0) { // if(idcounter==0) { // playerid[playeridcounter]=datafile.charAt(i); // } // if(idcounter>0) { // playerid[playeridcounter]=(playerid[playeridcounter]*10)+datafile.charAt(i); // } // } } if(datafile.charAt(i) == exclaim[1]) { // If the character is a comma if(testfornull == 0) { // If the comma means something playerdata.append(exclaim[1]); // Append it } commacounter++;// Increase the commacounter testfornull=1; // The next comma means nothing (guilty till proven innocent) unless we find data } if(datafile.charAt(i) == exclaim[0]) { // If the character is a newline commacounter=0;// Reset the commacounter state=1; // Set the state to 1 (beginning of the line) } } } } // UPDATE: ATP the program should have gathered all of the data from the weeks seperated by a comma on either side ie ,100,200,300,400, System.out.println(playerdata); // Update me on the playerdata variable StringBuffer almost = new StringBuffer(); // Create the string buffer to hold the new cut up data int start=0; // Create a start variable and initialize to 0 int length=0; // Create a length variable and initialize to 0 // Length needs to be removed and the following should work on commas with the starting position being the number of commas // Then as the loop runs through as soon as it gets to the starting spot it should append until it hits a comma and then // Stop immediately and not collect any more data System.out.println("Position=" + position); // Update me on the position information if(position==1) { // If position = 1 start=0; // Start is set to 2 (should be 1) CHANGE } if(position==2) { // The above applies to the rest of the ifs from here... start=3; } if(position==3) { start=6; } if(position==4) { start=8; } if(position==5) { start=10; } if(position==6) { start=12; } // ...until here start=start+playerposition; // System.out.println("Position 1"); System.out.println("Start=" + start + " Length=" + length + " Playerdata= " + playerdata); // Update me on important variables int counter=0; // Create a counter and set it to 0 int finish=0; // Create a variable to determine the finish point REMOVE CHANGE int ready=0; // Tell wether we are ready to collect data int almostready=0; int substart=0; // The character location to begin extracting data int done=0; for(int i=0; i < playerdata.length(); i++) { // Start the loop to determine where to cut the data // System.out.println(counter + "," + ready + "," + start + "," + finish + "," + playerdata.charAt(i)); if(almostready == 1) { ready=1; } if((counter == start) && (almostready == 0)) { // If the counter is at the right spot start // if(playerdata.charAt(i) == '(') { System.out.println("Starting to collect data at " + i); counter=0; // Reset the counter almostready=1; // Tell the program we're ready substart=i; // Make sure to start extracting from this point // } } if(playerdata.charAt(i) == exclaim[1]) { // If the character is a comma counter++; // Then increase the counter } if((playerdata.charAt(i) == exclaim[1]) || (playerdata.charAt(i) ==exclaim[0])) { // If the character is a comma and we are ready and have been collecting data if((ready == 1) && (done == 0)) { System.out.println("Found another comma quiting at " + i); finish=i; // Tell the program where to stop ready=0; almostready=2; done=1; } } } // finish--; // Get rid of the ending comma // substart++; // Get rid of the preceding comma System.out.println("Substart=" + substart + " Finish=" + finish); // Tell me what the program decided on for a start and finish almost.append(playerdata.substring(substart, finish)); // Append the appropriate sub string from the edited data file // StringBuffer end = new StringBuffer(almost.substring(0, almost.length()-1)); String returnvalue = new String(almost.toString()); // Set the returnvalue variable to the data we gathered System.out.println("return " + returnvalue); // Tell me what we have gathered return returnvalue; // Return it } public String[] getplayernamesonline(int teamid, int position) throws IOException { String filename = new String("http://webpages.charter.net/rrblock/data"+teamid+".dat"); URL ffilename = new URL(filename); String datafile = new String(onlineinput(ffilename, -1, 0)); // System.out.println(ffilename.getAbsolutePath()); // System.out.println(ffilename.canRead()); int newlinecounter=0; int playercounter=0; int idcounter=0; int playeridcounter=0; int commacounter=0; int state=0; StringBuffer[] playername = new StringBuffer[14]; int[] playerid = new int[14]; String exclaims = "\n,"; char[] exclaim; exclaim=exclaims.toCharArray(); int temp=0; int origcommacounter=0; for(int i = 0; playercounter < 14; i++) { if(playername[playercounter] == null) { playername[playercounter]=new StringBuffer(); } if(datafile.charAt(i) == exclaim[0]) { newlinecounter++; if(newlinecounter==3){ state=1; } } if(newlinecounter >= 3) { if(state==1) { if(datafile.charAt(i) != exclaim[1]) { if(commacounter==1) { playername[playercounter].append(datafile.charAt(i)); } if(commacounter==0) { if(idcounter==0) { playerid[playeridcounter]=datafile.charAt(i); } if(idcounter>0) { playerid[playeridcounter]=(playerid[playeridcounter]*10)+datafile.charAt(i); } } } if(datafile.charAt(i) == exclaim[1]) { temp=1; commacounter++; } if(commacounter==2) { playeridcounter++; playercounter++; state=2; } } if(state==2) { if(datafile.charAt(i) == exclaim[1]) { if(temp!=1) { commacounter++; } temp=0; } if(commacounter==18) { state=1; commacounter=0; } } } } String[] returnvalue = new String[3]; int x=0; int y=0; switch(position){ case 1:x=0;break; case 2:x=3;break; case 3:x=6;break; case 4:x=8;break; case 5:x=10;break; case 6:x=12;break; default:x=0;break; } if((position == 1) || (position ==2)) { int z = x + 3; for(; x 2) y=2; if(x > 13) x=13; returnvalue[y]=new String(playername[x].toString()); y++; } } else { int d = x + 2; for(; x