Have a Question ?

Home / Answered Questions / Other / java-write-code-to-ask-user-to-provide-input-length-in-miles-yards-feet-and-inches-and-write-code-to-aw415

(Solved): JAVA. Write Code To Ask User To Provide Input Length In Miles, Yards, Feet And Inches And Write Code...


JAVA. Write code to ask user to provide input length in miles, yards, feet and inches and write code to convert sum of total length into meters. Use the following formulas for the conversion to meters:

  • 1 inch = 0.0254 meters
  • 1 foot = 0.3048 meters
  • 1 yard = 0.9144 meters
  • 1 mile = 1609.3 meters

Display result by reiterating input values in inches, feet, yards, and miles entered by user, and the sum of the total length in meters.

This is what I have so far in BlueJ:

import java.util.Scanner;

public class Metric
{
public static void main(String[] args)
{
int input;
double meter;
final double INCH_TO_M = 0.0254;
final double FOOT_TO_M = 0.3048;
final double YARD_TO_M = 0.9144;
final double MILE_TO_M = 1609.3;

Scanner scan = new Scanner(System.in);
meter = 0;

System.out.print("Enter the lenght in inches: ");
inch = scan.nextInt();
meter += input*INCH_TO_M;
System.out.print("Enter the lenght in feet: ");
inch = scan.nextInt();
meter += input*FOOT_TO_M;
System.out.print("Enter the lenght in yard: ");
inch = scan.nextInt();
meter += input*YARD_TO_M;
System.out.print("Enter the lenght in miles: ");
inch = scan.nextInt();
meter += input*MILE_TO_M;
  
meter = inch*INCH_TO_M + foot*FOOT_TO_M + ...
"3 inches and 3 foot and 4 yards and 3 miles is equal 345.56 meters"

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



We have an Answer from Expert View Expert Answer

Expert Answer


CODE IN JAVA: Metric.java file: import java.util.Scanner; public class Metric { public static void main(String[] args) { // declaring variables int input;
We have an Answer from Expert
Buy This Answer $6

-- OR --

Subscribe To View Unlimited Answers
Subscribe $20 / Month