Results 1 to 5 of 5
  1. #1
    jbing109 is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Mph to Kph Algorithm

    Hi, I am working on a program that converts user input from mph to kph. It is for a long term project I am working on from a textbook to teach myself java. I am using a class called convert.class to convert a string to a double. So far I have:

    public class ConvertMphToKph
    {
    public static void main(String[] args)
    {
    double milesPK;
    milesPK = .6214;
    double kilometersPerHour, milesPerHour;
    convert.toNonNegativedouble(double kilometersPerHour);
    kilometersPerHour = milesPerHour / milesPK
    System.out.println(args[0]);
    }
    }
    My code doesnt work though. What am I doing wrong. Thanks.

    -Julie

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Mph to Kph Algorithm

    Hi,

    The first error is in the following line:

    Java Code:
    convert.toNonNegativedouble(double kilometersPerHour);
    First do you have the convert class with you? It better to name it Convert. When calling a method of a class you don't need to pass the type of the argument. In this case the double type. And on the next line you missed the semicolon at the end of your expression.

  3. #3
    jbing109 is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: Mph to Kph Algorithm

    Quote Originally Posted by wsaryada View Post
    Hi,

    The first error is in the following line:

    Java Code:
    convert.toNonNegativedouble(double kilometersPerHour);
    First do you have the convert class with you? It better to name it Convert. When calling a method of a class you don't need to pass the type of the argument. In this case the double type. And on the next line you missed the semicolon at the end of your expression.
    I'm not exactly sure what you mean. Should it be something like Convert.toNonNegativedouble() without the double kilometersPerHour? I thought for the argument to work you need a way for the user to call it. Thanks.

    -Julie

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Mph to Kph Algorithm

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

  5. #5
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Mph to Kph Algorithm

    When you call a method you only pass the argument such as:

    Java Code:
    Convert.toNonNegativedouble(kilometersPerHour);
    When you declare the method then you have to define the type such as:

    Java Code:
    public double toNonNegativedouble(double kilometersPerHour) {
    ...
    }

Similar Threads

  1. all i need is algorithm
    By naved in forum New To Java
    Replies: 4
    Last Post: 04-06-2011, 02:34 PM
  2. Algorithm help? :)
    By Mirix in forum New To Java
    Replies: 6
    Last Post: 05-24-2010, 02:08 AM
  3. Need some help in an algorithm
    By ea09530 in forum New To Java
    Replies: 3
    Last Post: 04-04-2010, 01:13 PM
  4. Help with an Algorithm
    By Manfizy in forum New To Java
    Replies: 22
    Last Post: 07-03-2009, 07:16 AM
  5. O(log n) algorithm help !!!!!!
    By itseeker87 in forum New To Java
    Replies: 8
    Last Post: 09-09-2008, 05:12 PM

Posting Permissions

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