# Convering Miles to kilometer

Page 1 of 1

## 6 Replies - 2032 Views - Last Post: 19 January 2013 - 09:37 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=219416&amp;s=dc9aded4152d2b75c03042a01569c2e2&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 flynhy

Reputation: 0
• Posts: 3
• Joined: 28-February 11

# Convering Miles to kilometer

Posted 28 February 2011 - 01:52 PM

Hi guys. I have to convert mile s to kilometrs and creating two classes and then put them into a table. I found few solutions but i don`t think they`re going to work for me.
There is what i have done so far and what i have to do.
Done so far:
```public static void main(Sting args[]){
double miles
miles = scan.netDouble();
Scanner scan = new Scanner(System.in);
System.out.println("Enter number of miles: ");
float km = miles * 1.609f;
System.out.println(miles = "miles is " + km + "kimometers.");
}
```
And then what i have to do:

Write a header file that contains the following two methods:
```/* convert from miles to kilometres */
Public static double mileToKilometer(double mile)

/* convert from kilometres to mile */
Public static double kilmeterToMile(double kilometre)
```
The formula for the conversion is:
Mile = 1.609 * kilometre
Implement the header file and write a test program that invokes these methods display the following tables:

Miles KiloMeters KiloMeters Miles
1.0 0.6215 20.0 32.180
2.0 1.2430 25.0 40.225
.....
10.0 6.2150 65.0 104.58

Analysis:
Describe the problem including input and output in your own words.

Design:
Describe the major steps for solving the problem

This post has been edited by japanir: 28 February 2011 - 03:18 PM
Reason for edit:: Added code tags

Is This A Good Question/Topic? 0

## Replies To: Convering Miles to kilometer

### #2 japanir

• jaVanir

Reputation: 1012
• Posts: 3,025
• Joined: 20-August 09

## Re: Convering Miles to kilometer

Posted 28 February 2011 - 03:30 PM

implement the code for converting miles to kms and kms to miles into the appropriate methods.
you have been given the prototypes, so just fill the body according the formulas you haave.
then, in the main method of the class, just call the methods instaed of using the code yourself.
Also, you have compile errors in the main methods.
first declare a Scanner and then use it.
at the end of a statement use ";", like:
```double miles;
```

### #3 flynhy

Reputation: 0
• Posts: 3
• Joined: 28-February 11

## Re: Convering Miles to kilometer

Posted 01 March 2011 - 09:22 AM

japanir, on 28 February 2011 - 03:30 PM, said:

implement the code for converting miles to kms and kms to miles into the appropriate methods.
you have been given the prototypes, so just fill the body according the formulas you haave.
then, in the main method of the class, just call the methods instaed of using the code yourself.
Also, you have compile errors in the main methods.
first declare a Scanner and then use it.
at the end of a statement use ";", like:
```double miles;
```

Thanks Japanir,
I`ll se what i`ll do and post again.

### #4 flynhy

Reputation: 0
• Posts: 3
• Joined: 28-February 11

## Re: Convering Miles to kilometer

Posted 07 March 2011 - 01:19 PM

I`m strugaling...
Can you give me a bit more hints Japanir?

### #5 pbl

• There is nothing you can't do with a JTable

Reputation: 8362
• Posts: 31,955
• Joined: 06-March 08

## Re: Convering Miles to kilometer

Posted 07 March 2011 - 07:56 PM

You should create your Scanner object before using it

miles = scan.netDouble();
Scanner scan = new Scanner(System.in);

### #6 kestrel

Reputation: -5
• Posts: 5
• Joined: 19-January 13

## Re: Convering Miles to kilometer

Posted 19 January 2013 - 09:35 PM

You can thank me later

### #7 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11235
• Posts: 42,271
• Joined: 27-December 08

## Re: Convering Miles to kilometer

Posted 19 January 2013 - 09:37 PM