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

I need to make a UnitConversionApplication that includes the ability of converti

ID: 3543830 • Letter: I

Question

I need to make a  UnitConversionApplication that includes the ability of converting Centimeters to Inches, Centimeters to Feet, Meters to Yards, and Kilometers to Miles by adding additional menu items.  The additional conversions will have their own methods as well.  The formulas are the opposite, instead of multiplying you will divide.  


Enter a number to convert: 10

Convert:
1. Inches to Centimeters     5. Centimeters to Inches
2. Feet to Centimeters       6. Centimeters to Feet
3. Yards to Meters           7. Meters to Yards
4. Miles to Kilometers       8. Kilometers to Miles

Enter your choice: 5

10 centimeters equals 3.93 inches.

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;

}


public double c2i()

{

return x/2.54;

}

public double c2f()

{

return x/30;

}

public double m2y()

{

return x/0.91;

}

public double k2m()

{

return x/1.6;

}


public void setX(int x)

{

this.x = x;

}


}



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 5. Centimeters to Inches 6. Centimeters to Feet 7. Meters to Yards 8. Kilometers to Miles");

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;

case 5:

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

break;

case 6:

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

break;

case 7:

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

break;

case 8:

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

break;

}

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

temp = scan.nextLine();

if(temp.equals("Y"))

{}

else

flag = false;

}

}

}