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

Create a class named Distance that contains two methods The first method should

ID: 3581866 • Letter: C

Question

Create a class named Distance that contains two methods The first method should he named feet To Meters. and should take in some number of feet and return the corresponding number of meters. The formula for this conversion is: m = 0.305 * ft the second method should be named meters To Feet and should take in some number of meters and return the corresponding number of feet. The formula for this conversion is: ft = 3.279 * m Also prepare a separate test main program that shows that your class and both methods work properly. Although partial credit will be awarded, important items for full credit are: Two Java files are created, one for the class and the other for the main test program. The main test program uses the correct syntax to call the methods in the class. All data to and from the methods are of type double.

Explanation / Answer

// Distance.java
public class Distance
{
   public static double feetToMeters(double feet)
   {
       return 0.305*feet;
   }

   public static double metersToFeet(double meters)
   {
       return 3.279*meters;
   }
}


// TestDistance.java
public class TestDistance
{
   public static void main(String[] args)
   {
       Distance d = new Distance();

       double meters = 5.5;
       System.out.println(meters + " m is " + d.metersToFeet(meters) + " ft");  

       double feet = 5.5;
       System.out.println(feet + " ft is " + d.feetToMeters(feet) + " m");  
   }
}


/*
output:

5.5 m is 18.0345 ft
5.5 ft is 1.6775 m

*/

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