# Mph to Kph Algorithm

• 01-21-2013, 05:40 AM
jbing109
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
• 01-21-2013, 06:25 AM
Re: Mph to Kph Algorithm
Hi,

The first error is in the following line:

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.
• 01-21-2013, 07:10 AM
jbing109
Re: Mph to Kph Algorithm
Quote:

Hi,

The first error is in the following line:

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
• 01-21-2013, 09:17 AM
DarrylBurke
Re: Mph to Kph Algorithm
• 01-21-2013, 09:26 AM
`Convert.toNonNegativedouble(kilometersPerHour);`
```public double toNonNegativedouble(double kilometersPerHour) { ... }```