149k views
3 votes
Write a program that declares named constants to represent the number of inches, feet, and yards in a mile. Also declare a variable to represent a number of miles and assign a value to it. Compute and display, with explanatory text, the value in inches, feet, and yards. Save the program as MileConversions.java.

User Jenny
by
5.1k points

1 Answer

3 votes

Answer:

// program in java.

// package

import java.util.*;

// class definittion

class MileConversions

{// main method of the class

public static void main (String[] args) throws java.lang.Exception

{

try{

// variables

final double inc_mile = 63360.0;

final double ft_mile = 5280.0;

final double yd_mile = 1760.0;

// Scanner object to read input

Scanner scr = new Scanner(System.in);

System.out.print("Enter miles: ");

// read miles from user

miles = scr.nextDouble();

//convert miles in inches,feet and yards

System.out.printf("%.1f miles is %.1f inches, or %.1f feet, or %.1f yards.", miles, miles*inc_mile, miles*ft_mile, miles*yd_mile);

}catch(Exception ex){

return;}

}

}

Step-by-step explanation:

Declare variable to store inches, feet and yards in one mile.Read the miles from user with scanner object.Convert miles into inches, feet and yards.Print these values.

Output:

Enter miles: 55

55.0 miles is 3484800.0 inches, or 290400.0 feet, or 96800.0 yards.

User MkV
by
5.7k points