Results 1 to 3 of 3

Thread: express string?

  1. #1
    jiml is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default express string?

    I this code I cobbled together;
    Java Code:
    import java.io.*;
    import java.util.*;
    import gov.usps.USPS4CB;
    
    public class jim {
        public String s1;
        public Integer firstArg;
        public String result;
        public String parseResult[];
        public String s2;
    
        public static void main(String [] args)throws IOException{
        	    if (args.length > 0) {
        	    	try{
        	    	    Integer firstArg = Integer.parseInt(args[0]);
        	       	    String s1 = "\"" + firstArg + "\"";
    		    String s2 = "" + s1;
    		    System.out.println(s1);
    		    System.out.println(s2);
    		}catch(NumberFormatException e) {
        	    	    System.err.println("Argument" + " must be an integer");
        	    	    System.exit(1);
        		}
        		    jim bob = new jim();
        		    bob.go();
        	    }
        }
           public void go(){
    	gov.usps.USPS4CB usps = gov.usps.USPS4CB.getInstance();
    	usps.setTrack("000000000000000000");
    	usps.setRoute(s1);
    	try {
    	String result = usps.getBarCode();
    	String[] parseResult = result.split("\\.");
    	System.out.println("\ntrackNo:\t" + usps.getTrack());
    	System.out.println("routeNo:\t" + usps.getRoute());
    	System.out.println("ReturnCode:\t" + parseResult[0]);
    	System.out.println("EncodedBarCode:\t" + parseResult[1]);
    	System.out.println(parseResult[1]);
    	}catch (IOException e1){
    	    System.out.println(e1);
    	}
     }
    
    }
    as you might imagine, I want the value of string s1 in usps.setRoute(s1). Any help?
    Last edited by jiml; 07-09-2012 at 08:58 PM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: express string?

    Rename your variables so that they are descriptive. And declare them just once. (Classes should also be named descriptively, and start with an UpperCaseLetter.)

    You declare a String s1 as an instance variable and then, later, declare another variable of the same name in the main() method. Every declaration creates a new variable. The intention seems to be that this string obtain a value in the main() method, but be used in the go() method - in that case there ought to be one variable involved, not two.

    The most tidy place for s1 to have its value assigned would be in a constructor.

  3. #3
    jiml is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default Re: express string?

    ok, asked and answered many questions; got this code working right;

    Java Code:
    import gov.usps.USPS4CB;
    
      class Coder {
          public static void main(String[] args) throws Exception {
    
              Integer firstArg = Integer.parseInt(args[0]);
    	  String RouteCode = "" + firstArg;
    	  gov.usps.USPS4CB usps = gov.usps.USPS4CB.getInstance();
              usps.setTrack("00000000000000000000");
              usps.setRoute(RouteCode);
              String result = usps.getBarCode();
              String[] parseResult = result.split("\\.");
    
              System.out.println("\ntrackNo:\t"      + usps.getTrack());
              System.out.println("routeNo:\t"        + usps.getRoute());
    
              System.out.println("ReturnCode:\t"     + parseResult[0]);
              System.out.println("EncodedBarCode:\t" + parseResult[1]);
          }
      }
    Thanks for your help.

    If anyone wants to use this, you just have to put your own routing code in usps.setTrack()
    Last edited by jiml; 07-10-2012 at 02:50 PM. Reason: how to use

Similar Threads

  1. sql server express + tomcat 7 + jtds driver
    By DJSKYLINE in forum JDBC
    Replies: 3
    Last Post: 07-14-2011, 10:11 AM
  2. Replies: 4
    Last Post: 09-07-2010, 06:51 AM
  3. Express 240 as'Two hundred and forty'
    By j3sr in forum New To Java
    Replies: 2
    Last Post: 01-28-2010, 11:11 AM
  4. SQL server express edition connection
    By pbaudru in forum JDBC
    Replies: 1
    Last Post: 01-19-2010, 09:59 AM
  5. how to properly express adding...
    By paul in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •