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

Write a program that prompts the user for a measurement in meters and then conve

ID: 3530297 • Letter: W

Question

Write a program that prompts the user for a measurement in meters and then converts it into miles, feet, and inches. Use a class public class Converter { /** Constructs a converter that can convert between two units. @param aConversionFactor the factor by which to multiply to convert to the target unit */ public Converter(double aConversionFactor) { . . . } /** Converts from a source measurement to a target measurement. @param fromMeasurement the measurement @return the input value converted to the target unit */ public double convertTo(double fromMeasurement) { . . . } /** Converts from a target measurement to a source measurement. @param toMeasurement the target measurement @return the value whose conversion is the target measurement */ public double convertFrom(double toMeasurement) { . . . } } In your ConverterTester class, construct and test the following Converter object: final double MILE_TO_KM = 1.609; Converter milesToMeters = new Converter(1000 * MILE_TO_KM);

Explanation / Answer

This is the exact answer to your question ...so check it out..and Rate only this one..Not above 2 junk answers..Please consider my effort..


Code starts form here

ConverterTest class

import java.util.Scanner;
public class ConveterTestClass {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
final double MILE_TO_KM = 1.609;
final double METER_TO_MILE =0.000621371;
final double METER_TO_FOOT =3.28084;
final double METER_TO_INCH=39.3701;
Converter metersToMiles = new Converter(METER_TO_MILE);
Converter metersToFoot = new Converter(METER_TO_FOOT);
Converter metersToInch = new Converter(METER_TO_INCH);
Scanner Sc=new Scanner(System.in);
int choice=0;
do
{

System.out.println("Enter the value in meters to Convert");
double value=Sc.nextDouble();
System.out.println("Enter to Unit : 1 : MILE 2 : FOOT 3 : INCH");
int unit=Sc.nextInt();
if(unit == 1)
{
metersToMiles.convertFrom(value);
System.out.println("The value of "+value+" meters in MILE is : "+metersToMiles.convertTo(value));
}
else if(unit == 2)
{
metersToFoot.convertFrom(value);
System.out.println("The value of "+value+" meters in FOOT is : "+metersToFoot.convertTo(value));
}
else if(unit == 3)
{
metersToInch.convertFrom(value);
System.out.println("The value of "+value+" meters in INCH is : "+metersToInch.convertTo(value));
}
else
{
System.out.println("Please enter a valid unit choice");
}

System.out.println("Lets do it againg.Press 1 if you widh to continue else press any other key ");
choice=Sc.nextInt();
}while(choice==1);

}
}


Converter Class



public class Converter {

/**
* @param args
*/
private double aConversionFactor;
private double fromMeasurement;
private double toMeasurement;
public Converter(double aConversionFactor) {
super();
this.aConversionFactor = aConversionFactor;
}
public double convertTo(double fromMeasurement)
{
this.toMeasurement=fromMeasurement*aConversionFactor;

return toMeasurement ;
}
public double convertFrom(double toMeasurement)
{
this.fromMeasurement =toMeasurement;
return this.fromMeasurement;
}
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}

Output :

Enter the value in meters to Convert
56
Enter to Unit :
1 : MILE
2 : FOOT
3 : INCH
1
The value of 56.0 meters in MILE is : 0.034796776
Lets do it againg.Press 1 if you widh to continue else press any other key
1
Enter the value in meters to Convert
34
Enter to Unit :
1 : MILE
2 : FOOT
3 : INCH
2
The value of 34.0 meters in FOOT is : 111.54856
Lets do it againg.Press 1 if you widh to continue else press any other key
1
Enter the value in meters to Convert
56
Enter to Unit :
1 : MILE
2 : FOOT
3 : INCH
3
The value of 56.0 meters in INCH is : 2204.7256
Lets do it againg.Press 1 if you widh to continue else press any other key
2



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