Actually, a small correction needed 1 Yard=0.0009144 Kms and 1 Yard= 0.9144 metres
1. Accepting a user input whether YardtoKilo( ) function called or kilotoYard() called with a choice of 1 and 2 respectively otherwise error message is displayed.
2. Accepting a double value from the user for conversion as ip1 and ip2
3. calling the respective function and returning the result.
4. Displaying back to the console
We use this BigDecimal.valueOf(a).toPlainString() for precision of resultant values.
Program:
import java.util.*;
import java.math.BigDecimal;
public class Main
{
public static double YardtoKilo(double yards)
{
return (yards*0.0009114);
}
public static double KilotoYard(double kms)
{
return (kms/0.9114);
}
public static void main(String[] args)
{
Scanner src=new
Scanner(System.in);
System.out.println("Please enter
your choice");
System.out.println("1.YardtoKilo\t2.KilotoYard");
int choice=src.nextInt();
if(choice==1)
{
System.out.println("Please enter
the Yards");
double ip1=src.nextDouble();
double a=YardtoKilo(ip1);
System.out.println(BigDecimal.valueOf(a).toPlainString()+"kms");
}
else if(choice==2)
{
System.out.println("Please enter
the Kilometres");
double ip2=src.nextDouble();
double a=KilotoYard(ip2);
System.out.println(BigDecimal.valueOf(a).toPlainString()+"yards");
}
else
{
System.out.println("Wrong
choice");
}
}
}
Output:
Hope this helps!!!
Write a program that contains functions YardtoKilo( ) to convert Yard to Kilometers and kilotoYard() Kilometers...
Write a program that will convert miles to kilometers and kilometers to miles. The user will indicate both a number (representing a distance) and a choice of whether that number is in miles to be converted to kilometers or kilometers to be converted to miles Each conversion is done with a value returning function You may use the following conversions. 1 kilometer = .621 miles 1 mile = 1.61 kilometers Sample Run: Please input Convert miles to kilometers Convert kilometers...
k2m.cpp Write a program which converts kilometers to miles and miles to kilometers. Input value (m or km)is in argv[1] Program is accessed by "k2m" or "m2k", using Unix' ability to assign SYMBOLIC LINKS to files, so they have multiple names. The program knows to do kilometers -> or miles -> km by examining its name in argv[0]. (It does a string comparison on argv[0]). Miles to kilometers: m2k Kilometers to miles: k2m If you're developing on a Windows machine...
MATLAB - create MATLAB functions to convert kilometers to miles and vice versa according to the following conditions. (a) The functions created will have input of miles or kilometers and the output with converted kilometers or miles. (b) The output of the function should be a conversion table. No input for the function is needed. (1 mile = 1 609.344 meter) - function with the following: (1) output a third-order polynomial function with the coefficients as the input variables; (2)...
POWERSHELL: Write Multiple Functions in a script call ConversionFunctions.ps1 The first function script ConvertToFeet($meters) is given as an example. Please complete ConvertToFahrenheit, ConvertTocelsius, ConvertToMiles, ConvertToKilometers ConversionFunctions.ps1 Function Script:ConvertToFeet($meters) { # Convert meters into to Feet # 1 meter = (1 * 3.28) feet "$meters meters equals $($meters * 3.28) feet“ } #end ConvertToFeet Function Script:ConvertToFahrenheit($celsius) { # Convert celsius into Fahrenheit # 1 celsius = ((1.8 * 1) + 32) fahrenheit "write your answer here" } #end ConvertToFahrenheit Function Script:ConvertTocelsius($fahrenheit)...
java programming Problem 2) Convert Kilometers to Miles Write a JavaFX program using JavaFX Menu for to solve the following problem about converting between Kilometers to Miles. Sample Run is shown below You are asked to implement only the menu item under Formulas which reads as"KM to Mile". Choosing this menu item will display the following input box: Input Enter Kilometers Value OK Cancel The result will be displayed in a TextArea as shown below: JavaF× Menu Example " File...
This is a basic java program where you convert units using only loops, control statements and format modifiers: Create a Java program named UnitConversion.java that converts the following: 1. Liter to gallon 2. Gallon to liter 3. Kilometers to miles 4. Miles to kilometers The conversion formulas: 1 liter = 0.264172 gallon 1 gallon = 3.78541 liters 1 kilometer = 0.621 miles I mile = 1.609 kilometers
Use functions to complete this C + + program You want to write a converter program which will let user convert distance and weight from SI to the USCS system and vice versa The formulae are as follows: 1. Distance in miles- distance in kilometers x 1.60 2. Weight in kilograms weight in pounds x 2.20 The program would let user input the number that they want to convert and then choose the units to and from which they want...
Using Atmel Studios Write an AVR program that convert a distance reading in Miles (variable Mi) to Kilometer (variable Km). Include .INCLUDE <m328pdef.inc>
Using Functions: Conversion Program: Write a program that perform conversions that we use often. Program should display the following menu Welcome to the Conversion Program =============================== Fahrenheit to Celsius Miles to kilometers Liters to Gallons Exit from the program You should implement this program using functions and your program need to have following functions void displayMenu() double fahrenheitToCilsuis(double fTemp) double milesToKilometers(double miles) double litersToGallons(doube liters)
Python Programing : Convert to binary - functions Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a...