Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Oct 3rd, 2005, 11:28 PM   #1
lloydkirk
Newbie
 
Join Date: Oct 2005
Posts: 7
Rep Power: 0 lloydkirk is on a distinguished road
can't compile code

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 ();
   
      
   }

}
}
lloydkirk is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC