A friend of mine gave me some java code and some basic directions. Unfortunately, I can't get it to compile or execute. I would realy appreciate it if you guys could help me out. Im an absolute newb when it comes to java. :o
Maybe someone could compile it for me. Also, when he says to "run it with java VS 'id number', how is that done and where is it executed? Im guessing its supposed to be typed in the command prompt, but im not sure of the directory...Thanks for your help!
Directions
Quote:
Go to http://www.84silver.com/contest_browse_finals.php and select a calculator to vote for. The 'calculator ID' is shown at the end of the URL, eg 411 for Washington. Extract the code to 'VS.java' (case matters). Compile the code, and run it with java VS 'id number'.
eg
java VS 1161
to vote for Florida. 1 or 2 votes are cast per second.
|
Code:
import java.util.*;
import java.io.*;
import java.net.*;
public class VS{
public static void main(String[] args) throws Exception{
String calcID;
System.out.print("\n***TI Vote-stuffer**\n");
if(args.length==0){
System.out.print("\n\nPlease enter a calculator-ID to vote for");
System.out.print("\nas a parameter! eg 'java VS 123'");
System.out.print("\nyou may find the ID by clicking on an entry on TI's web site");
return;
}
calcID=args[0];
System.out.print("\n\nUsing calculator ID: " + calcID+"\n\n");
URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream input;
while(true){
Thread.sleep(500);
// URL of CGI-Bin script.
url = new URL ("http://www.84silver.com/contest_vote_finals.php");
// URL connection channel.
urlConn = url.openConnection();
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// Send POST output.
printout = new DataOutputStream (urlConn.getOutputStream ());
String content =
//"calculator_id=" + URLEncoder.encode ("1161") +
"calculator_id=" + URLEncoder.encode (calcID) +
"&vote_for_this_one=" + URLEncoder.encode ("Vote!");
printout.writeBytes (content);
printout.flush ();
printout.close ();
// Get response data.
input = new DataInputStream (urlConn.getInputStream ());
String str;
while (null != ((str = input.readLine())))
{
System.out.println (str);
}
input.close ();
}
}
}