# Thread: Mph to Kph Algorithm

1. Member
Join Date
Jan 2013
Posts
2
Rep Power
0

## 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. Senior Member
Join Date
Jun 2007
Location
Bali, Indonesia
Posts
762
Rep Power
10

## 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. Member
Join Date
Jan 2013
Posts
2
Rep Power
0

## 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.
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. ## Re: Mph to Kph Algorithm

5. Senior Member
Join Date
Jun 2007
Location
Bali, Indonesia
Posts
762
Rep Power
10

## 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) {
...
}```

#### Posting Permissions

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