Write a program that contains the following two methods: /** Convert from feet to meters */ public static double footToMeter (double foot) /** Convert from meters to feet */ public static double meterToFoot (double meter) The formula for the conversion is : meter

Answer :

Complete Question:

Write a program that contains the following two methods:

/** Convert from feet to meters */

public static double footToMeter(double foot)

/** Convert from meters to feet */

public static double meterToFoot(double meter)

The formula for the conversion is: meter = 0.305 * foot and foot = 3.279 * meter Write a test program that invokes these methods. PLEASE WRITE IN JAVA.

Answer:

//Declare the class

public class Converter{

   

    //method footToMeter that receives the foot as parameter

    public static double footToMeter(double foot){

        //declare a double variable called meter,

        //to hold the result of the conversion

        double meter;

       

        //using the given formula, conver the foot to meter and

        //store the result in the meter variable

        meter = 0.305 * foot;

       

        //return the result stored in meter

        return meter;

    }

   

   

    //method meterToFoot that receives the meter as parameter

    public static double meterToFoot(double meter){

        //declare a double variable called foot,

        //to hold the result of the conversion

        double foot;

       

        //using the given formula, convert the meter to foot and

        //store the result in the foot variable.

        foot = 3.279 * meter;

       

        //return the result stored in foot.

        return foot;

    }

   

   

    //Test program to invoke those methods

    public static void main(String []args){

           

           //Convert 120 feet to meter

           System.out.println("120 feet to meter is " + footToMeter(120));

           

           //Convert 36 meters to foot

           System.out.println("36 meters to feet is " + meterToFoot(36));

    }

   

   

}  //End of class declaration

Sample Output:

120 feet to meter is 36.6

36 meters to feet is 118.044

Explanation:

The above code has been written in Java and it contains comments explaining each line of the code. Please go through the comments.

There is also a sample output from the run of the code.

An screenshot containing the program and the output has also been attached to this response.

${teks-lihat-gambar} stigawithfun

Other Questions