Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to create an application that converts English units of measurements to m

ID: 3543829 • Letter: I

Question

I need to create an application that converts English units of measurements to metric units.  The application will display a menu similar to the example dialogue whereby the user will enter a value and then select the conversion.  The application will then ask if there is another conversion.  The application should include separate methods for doing each of the conversions.  

Formulas:

Centimeters = inches*2.54
Centimeters=feet*30
Meters=yards*0.91
Kilometers=miles*1.6

Example:

Enter a number to convert: 10

Convert:
1. Inches to Centimeters
2. Feet to Centimeters
3. Yards to Meters
4. Miles to Kilometers

Enter your choice: 1

10 inches equals 25.4 centimeters.

Explanation / Answer

/* package whatever; // don't place package name! */


import java.util.*;

import java.lang.*;

import java.io.*;


class convert

{

private double x;

convert(double x)

{

this.x = x;

}

public double i2c()

{

return 2.54*x;

}

public double f2c()

{

return x*30;

}

public double y2m()

{

return x*0.91;

}

public double m2k()

{

return x*1.6;

}

}



class driver

{

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

{

boolean flag =true;

String temp;

Scanner scan = new Scanner(System.in);

System.out.println("Enter a number to convert: ");

double x = new Double(scan.nextLine());

convert c = new convert(x);

System.out.println("Convert: 1. Inches to Centimeters 2. Feet to Centimeters 3. Yards to Meters 4. Miles to Kilometers");

while(flag)

{

System.out.println("Enter your choice:");

int a = new Integer(scan.nextLine());

switch(a)

{

case 1:

System.out.println(x + " Inches equals "+c.i2c()+ " Centimeters");

break;

case 2:

System.out.println(x + " Feet equals "+c.f2c()+ " Centimeters");

break;

case 3:

System.out.println(x + " Yards equals "+c.y2m()+ " Meters");

break;

case 4:

System.out.println(x + " Miles equals "+c.m2k()+ " Kilometers");

break;

}

System.out.println("Do you want Another Conversion (Y/N)? ");

temp = scan.nextLine();

if(temp.equals("Y"))

{}

else

flag = false;

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote