Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-06-2005, 01:31 PM   #1 (permalink)
Kernel_Killer
Regular Contributor
 
Kernel_Killer's Avatar
 
Join Date: Feb 2003
Location: indisclosed
Posts: 210
Kernel_Killer is on a distinguished road
Wrapper to String

I'm trying to convert a wrapper back to string, but for some reason I can't seem to get my variable to drop into my method correctly. Here's what I have:

Conversion.java (Java Class File)
Code:
/*
 * Conversion.java
 *
 * Created on March 2, 2005, 6:38 PM
 */

package Chapter6Project1;


public class Conversion 
{
    
    /** Creates a new instance of Conversion */
    public Conversion() 
    {
    }  
    
    public Integer stringToInteger1(String s) throws Exception 
    {
        int i = Integer.parseInt(s);    
            
        Integer iwResult = new Integer(i);
        
        System.out.println(i);
        return iwResult;
    }
    
    public Double stringToDouble1(String t) throws Exception
    {
        double d = Double.parseDouble(t);
        
        Double iwResult2 = new Double(d);
        
        System.out.println(d);
        return iwResult2;
    }
    
    public String wrapperToString(Integer u) throws Exception
    {
        
        String str = u.toString();
        String iwResult3 = new String(str);
        System.out.println("test " + str + iwResult3 + u);
       // String iwResult3 = toString(sresult);
        return iwResult3;
    }
    
}
ConversionTester.java (Main)
Code:
package Chapter6Project1;

public class ConversionTester
{
    public ConversionTester()
    {
        
    }

    public static void main(String[] args) throws Exception
    {
            Conversion aConversion = new Conversion();
            aConversion.stringToInteger1("5");
            aConversion.stringToDouble1("5.5");
            aConversion.wrapperToString("6");
           // aConversion.wrapperToString("8");
            Integer u = new Integer("6");
            
    }
}
As you can see, I can pass the Integer and Double through thier methods, but for some reason the wrapperToString method I can't exactly pass and Integer through (hence the commented out aConversion statement in the ConversionTester file).

TIA
__________________
Network Synapse
Screaming Electron
Kernel_Killer is offline   Reply With Quote
Old 03-06-2005, 02:02 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,139
Belisarius is on a distinguished road
In wrapperToString, where do you define "sresult"? Also, you don't define the method "toString" anywhere. As an Object, it inherits a "toString()" method, one that doesn't take any arguments.

Additionally, you don't need to do all those method calls just to turn a String into an Integer or Double. Both of those objects take a String for a constructor.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 03-06-2005, 07:09 PM   #3 (permalink)
Kernel_Killer
Regular Contributor
 
Kernel_Killer's Avatar
 
Join Date: Feb 2003
Location: indisclosed
Posts: 210
Kernel_Killer is on a distinguished road
Whoops. Sorry about that, didn't put my latest version of that last method.

Code:
public String wrapperToString(Integer u) throws Exception
{
          String str = u.toString();
          String iwResult3 - new String(str);
          System.out.println(str);
          return iwResult3;
}
I'm at a lost. I checked the Java Doc on toString, and I'm not quite sure what I'm missing. Surely it's how I'm pushing it into the method? I guess I should do it a bit different from my primitive data types to string methods?
__________________
Network Synapse
Screaming Electron
Kernel_Killer is offline   Reply With Quote
Old 03-06-2005, 08:11 PM   #4 (permalink)
Kernel_Killer
Regular Contributor
 
Kernel_Killer's Avatar
 
Join Date: Feb 2003
Location: indisclosed
Posts: 210
Kernel_Killer is on a distinguished road
Ok. Got it.

Code:
package Chapter6Project1;

public class ConversionTester
{
    public ConversionTester()
    {
        
    }

    public static void main(String[] args) throws Exception
    {
            Conversion aConversion = new Conversion();
            aConversion.stringToInteger1("5");
            aConversion.stringToDouble1("5.5");
            Integer u = new Integer(6);
            aConversion.wrapperToString(u);
    }
}
I had to put my Integer statement before, and then pass the variable as a variable to the aConversion instead of a straight int variable.

Thanx Bel.
__________________
Network Synapse
Screaming Electron
Kernel_Killer is offline   Reply With Quote
Reply

Bookmarks

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for another program Androto Standard C, C++ 54 10-15-2004 07:21 AM
sorting objects arrays by object properties sde Java 28 08-05-2004 05:51 AM
From C to Java HighterDK Java 11 07-13-2004 07:15 PM


All times are GMT -8. The time now is 01:45 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting