4-9 SpeedConverter

posted Feb 23, 2014, 1:38 PM by Dlovan ismail   [ updated Feb 23, 2014, 1:38 PM by Karwan Jacksi ]
//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);
            }
        
    }  
}

ċ
SpeedConverter.java
(1k)
Karwan Jacksi,
Feb 23, 2014, 1:38 PM
Comments