4-9 SpeedConverter

Post date: Feb 23, 2014 9:38:07 PM

//This program displays a table of speeds in kph converted to mph.

package speedconverter;

public class SpeedConverter

{

public static void main(String[] args)

{

//Constants

final int STARTTING_KPH = 60; //Starting speed

final int MAX_KPH = 130; //Maximum speed

final int INCREMENT = 10; //Speed increment

//Variables

int kph; //to hold the speed in kph.

double mph; //to hold the speed in mph;

// Display the table headings.

System.out.println("kph\t\tmph");

System.out.println("--------------------");

// Display the speeds.

for (kph = STARTTING_KPH; kph <= MAX_KPH; kph += INCREMENT)

{

// Calculate the mph.

mph = kph * 0.6214;

// Display the speeds in kph and mph.

System.out.printf("%d\t\t%.1f\n", kph, mph);

}

}

}