Results 1 to 4 of 4

Thread: Converter Class

  1. #1
    FOX427 is offline Member
    Join Date
    Jun 2011
    Posts
    54
    Rep Power
    0

    Post Converter Class

    Hi All! i am having problem with implementing converter class, simple program(not for me) that requires the program to prompt user for a measurement in meters and then converts it into miles, feet, and inches. I started implementing but I need your help guys to find out what's wrong here...I will be thankful to any suggestions, Here is the code:
    Converter Class:
    Java Code:
    
    public class Converter {
    	/**
    	 * Constructs a converter that can convert between two units.
    	 * @param aConversionFactor the factor by which 
    	 * to multiply to convert to the target unit.
    	 */
    	public Converter(double aConversionFactor)
    	{
    		
    	}
    	/**
    	 * Converts from a source measurement to a target measurement.
    	 * @param fromMeasurement the measurement
    	 * @return the input value converted to the target unit
    	 */
    	public double convertTo(double fromMeasurement)
    	{
    		double toMilesfromMeters = fromMeasurement/1.609;
    		return toMilesfromMeters;
    		
    	}
    	/**
    	 * Converts from a target measurement to a source measurement.
    	 * @param toMeasurement the target measurement
    	 * @return the value whose conversion is the target measurement
    	 */
    	public double convertFrom(double toMeasurement)
    	{
    		return toMeasurement;
    		
    	}
    
    }
    ConverterTester Class:
    Java Code:
    public class ConverterTester {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		final double MILE_TO_KM = 1.609;
    		Converter milesToMeters = new Converter(1000*MILE_TO_KM);
    		milesToMeters.convertTo(1000);
    		System.out.println(milesToMeters);
    		
    
    	}
    
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Converter Class

    Quote Originally Posted by FOX427 View Post
    I need your help guys to find out what's wrong here.
    Everything. Nothing.

    You tell us. Does it compile? Does it run? Does it produce expected results?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    FOX427 is offline Member
    Join Date
    Jun 2011
    Posts
    54
    Rep Power
    0

    Default Re: Converter Class

    sorry for incomplete info, indeed, it is compiling and running, but result is strange: "Converter@58c9e870". Dont know what does it mean.....

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Converter Class

    Look closely at what you're printing. It's an instance of a class that doesn't override Object's toString() method.

    Read the API for that method i.e. Object#toString() to see what it returns.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. I need some help with converter GUI
    By linux1man in forum AWT / Swing
    Replies: 5
    Last Post: 07-30-2009, 12:57 AM
  2. YaHP Converter 1.2.17
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-06-2007, 04:11 PM
  3. YaHP Converter 1.2.15
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-19-2007, 06:09 PM
  4. YaHP Converter 1.2.14
    By Jamie in forum Java Software
    Replies: 0
    Last Post: 06-16-2007, 10:35 AM
  5. YaHP Converter 1.2.13
    By Jamie in forum Java Software
    Replies: 0
    Last Post: 06-14-2007, 04:05 PM

Tags for this Thread

Posting Permissions

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