In: Computer Science
Submit convertToMetric.java and testConvertToMetric.java as attachments under Assignment Submission.
if you could provide an idiot proof walkthrough i would appreciate it. im having problems with textpad compiling and running the programs. Thank you
/*
* Java program that prompts the user to enter the length value for
feet
* and then display the meters and centimeters of the corresponding
feet
* on the java console window.
* */
//testConvertToMetric.java
import java.util.Scanner;
public class testConvertToMetric
{
public static void main(String[] args)
{
//Create a Scanner class
object
Scanner scan=new
Scanner(System.in);
System.out.print("Enter standard
value(in feet) : ");
//read feet value from
console
double
feet=Double.parseDouble(scan.nextLine());
//Create an object of
convertToMetric class
convertToMetric obj=new
convertToMetric(feet);
//call getCentimeters
System.out.printf("%.2f Foot= %.2f
Centimeter\n",feet,obj.getCentimeters());
//call getMeters
System.out.printf("%.2f feet= %.2f
Meter\n",feet,obj.getMeters());
}
}
-------------------------------------------------------------------------------------------------
//convertToMetric.java
public class convertToMetric
{
//instance variable
private double length;
/*constructor that takes length as input
* and set length to this class length*/
public convertToMetric(double length)
{
setStandard(length);
}
/*Method to set the standard field, length */
public void setStandard(double length)
{
this.length=length;
}
/*Method returns the standard field, length */
public double getStandard()
{
return length;
}
/*Method that returns the converted feet to
meters*/
public double getMeters()
{
//conversion factor from feet to
meter
final double
FEET_TO_MTR=0.3048;
return length*FEET_TO_MTR;
}
/*Method that returns the converted cms of feet
value*/
public double getCentimeters()
{
//conversion factor from feet to
cms
final double
FEET_TO_CM=30.48;
return length*FEET_TO_CM;
}
}//end of the class
-------------------------------------------------------------------------------------------
Sample program output screenshot :