Respuesta :
Answer:
The program with all the functions implemented in Java programming language is given in the explanation section
Explanation:
import java.util.Scanner;
public class num11 {
public static double feetToInches(double feet){
return feet*12;
}
public static double inchesToFeet(double inches){
return inches/12;
}
public static double feetToYard(double feet){
return feet/3;
}
public static double yardToFeet(double yard){
return yard*3;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter length in feet");
double lenFeet = in.nextDouble();
System.out.println("The equivalent in Inches is "+feetToInches(lenFeet));
System.out.println("The equivalent in yard is "+feetToYard(lenFeet));
System.out.println("enter value in Inches");
double lenInches = in.nextDouble();
System.out.println("The equivalent feet is "+inchesToFeet(lenInches));
System.out.println("enter value in Yards");
double lenYard = in.nextDouble();
System.out.println("The equivalent feet is "+yardToFeet(lenYard));
}
}
Explanation:
One line simple functions are created. The four functions ft2inc, inc2ft, ft2yd, and yd2ft convert feet to inches, inches to feet, feet to yards, and yards to feet respectively. Then in the test code, input is taken from the user and each function is called one by one. eval is used to ensure numeric input from the user. The program is tested multiple times and it returns correct results.
Python Functions:
def ft2inc(ft):
return print("Feet to Inches: ",ft*12)
def inc2ft(inc):
return print("Inches to Feet: ",inc/12)
def ft2yd(ft):
return print("Feet to Yards: ",ft/3)
def yd2ft(yd):
return print("Yards to Feet: ",yd*3)
Test Code:
ft=eval(input("Conversion Feet to Inches: "))
ft2inc(ft)
inc=eval(input("Conversion Inches to Feet: "))
inc2ft(inc)
ft=eval(input("Conversion Feet to Yards: "))
ft2yd(ft)
yd=eval(input("Conversion Yards to Feet: "))
yd2ft(yd)
Output:
Conversion Feet to Inches: 2
Feet to Inches: 24
Conversion Inches to Feet: 48
Inches to Feet: 4.0
Conversion Feet to Yards: 9
Feet to Yards: 3.0
Conversion Yards to Feet: 12
Yards to Feet: 36