Fabay J.
asked 08/08/17Create a java program that will asks the user's height in centimeters and display the equivalent feet and inches.
1 Expert Answer
Patrick B. answered 07/16/19
Math and computer tutor/teacher
import java.io.*;
class CentimetersToEnglish
{
private double cm;
private int feet;
private int inches;
private int fractionOfInch;
private Console console;
CentimetersToEnglish()
{
console = System.console();
cm=0;
feet=inches=fractionOfInch=0;
}
//do you want fractions of an inch??? Ex. 2.4 inches = 2 and 7/16 inch
private void Lookup(double fracIn)
{
}
public void Go()
{
String inbuff;
try
{
cm=-1;
while (cm<0)
{
System.out.print(" Please input the height in centimeters :>");
inbuff = console.readLine();
cm = Double.parseDouble(inbuff);
}
double rawInches = cm / 2.54; // 1 inch = 2.54 centimeters
feet = (int) (rawInches/12); //1 foot = 12 inches
double rawInch = rawInches - feet*12;
inches = (int) (rawInch);
// Lookup(rawInch - inches);
System.out.println(cm + " centimeters = " + feet + " feet and " + inches + " inches");
} //try
catch (Exception ex)
{
System.out.println(" Input error occurs ");
}
} //Go
public static void main(String args[])
{
CentimetersToEnglish myConverter = new CentimetersToEnglish();
myConverter.Go();
} //main
} //class
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Fabay J.
08/09/17