
Fabay J.
asked 07/20/17create a java program that will ask the user's height in centimeters and display the equivalent feet and inches.
create a java program that will ask the user's height in centimeters and display the equivalent feet and inches.Possible output should be:
Please enter your height(cms):______
Your height is _______cm,s and it is equivalent to __________feet and inches.
More
2 Answers By Expert Tutors
Michael J. answered 07/20/17
Tutor
5
(5)
Effective High School STEM Tutor & CUNY Math Peer Leader
Try this code:
var unit = "number"
var height = function(unit) {
var height = function(unit) {
prompt("Please enter your height!");
console.log(unit + " " + "centimeters.");
{
height = unit * 0.0328;
}
console.log(height + " " + "feet")
{
height = unit / 2.54;
}
console.log(height + " " + "inches")
}
Fabay J.
i try this code but. it says that editor does not contain a main type
Report
08/09/17

Andy C. answered 07/20/17
Tutor
4.9
(27)
Math/Physics Tutor
import java.io.Console;
class EnglishMetricMeasurements
{
/**********************************************************
//nested class : used to convert the decimal measurement
// into fractions of an inch; on the standard
// ruler, the inch is divided into 16 equal pieces;
//
// EXAMPLE. 1/2 inch = 1/2" = 0.5
// So the call is inch16(1,2,0.5f);
//
// EXAMPLE 10/16 = 5/8 = 0.625, so call inch16(5,8,0.625f);
//
******************************************************************************/
private class inch16
{
int numerator;
int denominator;
double fNumAmt;
inch16(int n, int d, double flAmt)
{
numerator = n;
denominator = d;
fNumAmt = flAmt;
}
int getNumerator() { return(numerator); }
int getDenominator() { return(denominator); }
double getDecimalAmt() { return(fNumAmt); }
}
private double centimeters;
private int feet;
private int inches;
private inch16 myInch16;
private inch16[] inch16_table = new inch16[16];
public double getCentimeters() { return(centimeters); }
public int getFeet() { return(feet); }
public int getInches() { return(inches); }
public void setCentimeters( double cm) { centimeters = cm; }
EnglishMetricMeasurements()
{
centimeters = 0;
feet=0;
inches = 0;
//sets up the table
inch16_table = new inch16[16];
inch16_table[0] = new inch16(0,1,0);
inch16_table[1] = new inch16(1,16,0.0625f);
inch16_table[2] = new inch16(1,8,0.125f);
inch16_table[3] = new inch16(3,16,.1825f);
inch16_table[4] = new inch16(1,4,0.25f);
inch16_table[5] = new inch16(5,16,0.3125f);
inch16_table[6] = new inch16(3,8,0.375f);
inch16_table[7] = new inch16(7,16,0.4375f);
inch16_table[8] = new inch16(1,2,0.5f);
inch16_table[9] = new inch16(9,16,0.5625f);
inch16_table[10] = new inch16(5,8,0.625f);
inch16_table[11] = new inch16(11,16,0.6875f);
inch16_table[12] = new inch16(3,4,0.75f);
inch16_table[13] = new inch16(13,16,0.8125f);
inch16_table[14] = new inch16(7,8,0.875f);
inch16_table[15] = new inch16(15,16,0.93755f);
}
/****************************************************************
//linear searches the inch16 table for the first measurement
// that is GREATER than the decimal measurement; returns
// the inch16 obj if it is there; returns NULL otherwise
// which means rounds to the next inch.
// EXAMPLE inch16_lookup(0.4235) returns 7/16 or {7,16,0.4375}
// EXAMPLE inch16_lookup(0.8894) returns 16/16 or {15,16,0.9.7375}
// EXAMPLE inch16_lookup(0.4567) returns 1/2 or {1,2,0.5}
// EXAMPLE inch16_lookup(0.98765) returns NULL, so you
// must round up to the next whole inch
*********************************************************************/
public inch16 inch16_lookup( double decimalMeasurement)
{
inch16 inch16ObjReturn = null;
for (int iLoop=0; iLoop<16; iLoop++)
{
//System.out.println("inch16_lookup : iLoop = " + iLoop);
if (inch16_table[iLoop].getDecimalAmt()>=decimalMeasurement)
{
inch16ObjReturn = inch16_table[iLoop];
break;
}
}
return(inch16ObjReturn);
}
private void input()
{
Console console = System.console();
System.out.print(" Please input the height in centimeters :>");
String inbuff = console.readLine();
centimeters = Double.parseDouble(inbuff);
//System.out.println(" Input measurement in centimeters = " + centimeters);
}
private void output()
{
System.out.println(" The measurement in centimeters is " + centimeters);
System.out.println(" The measurement in english measure is ");
System.out.print( feet + " feet : " + inches + " ");
if (myInch16 != null)
{
System.out.print( myInch16.getNumerator() + "\\" + myInch16.getDenominator() );
}
System.out.println(" inches");
}
private void convertMetricCentimetersToEnglishMeasures()
{
// first changes centimeters to inches: 1 inch = 2.54 centimeters;
double Inches = centimeters / 2.54;
//throws stores the same result as an integer with no decimals
int iInches = (int) (Math.floor(Inches));
// next changes inches to feet
feet = (int) (iInches / 12);
inches = (int) (iInches % 12); // whole inches
double fractionInch = Inches - iInches; //fraction of the inch
myInch16 = inch16_lookup(fractionInch);
if (myInch16 != null)
{
// found the fraction of the inch by rounding up to the nearest 16th of the inch
}
else
{
feet++;
inches = 0;
}
} // convertMetricCentimetersToEnglishMeasure
public static void main(String args[])
{
EnglishMetricMeasurements X = new EnglishMetricMeasurements();
if (args.length==0) //centimeters not given on the command line
{
X.input(); //prompts the user to input the measurement in centimeters
}
else // measurement in centimeters given on the command line
{
double cm = Double.parseDouble(args[0]);
X.setCentimeters(cm);
}
X.convertMetricCentimetersToEnglishMeasures();
X.output();
}
} //class EnglishMetricMeasurements
class EnglishMetricMeasurements
{
/**********************************************************
//nested class : used to convert the decimal measurement
// into fractions of an inch; on the standard
// ruler, the inch is divided into 16 equal pieces;
//
// EXAMPLE. 1/2 inch = 1/2" = 0.5
// So the call is inch16(1,2,0.5f);
//
// EXAMPLE 10/16 = 5/8 = 0.625, so call inch16(5,8,0.625f);
//
******************************************************************************/
private class inch16
{
int numerator;
int denominator;
double fNumAmt;
inch16(int n, int d, double flAmt)
{
numerator = n;
denominator = d;
fNumAmt = flAmt;
}
int getNumerator() { return(numerator); }
int getDenominator() { return(denominator); }
double getDecimalAmt() { return(fNumAmt); }
}
private double centimeters;
private int feet;
private int inches;
private inch16 myInch16;
private inch16[] inch16_table = new inch16[16];
public double getCentimeters() { return(centimeters); }
public int getFeet() { return(feet); }
public int getInches() { return(inches); }
public void setCentimeters( double cm) { centimeters = cm; }
EnglishMetricMeasurements()
{
centimeters = 0;
feet=0;
inches = 0;
//sets up the table
inch16_table = new inch16[16];
inch16_table[0] = new inch16(0,1,0);
inch16_table[1] = new inch16(1,16,0.0625f);
inch16_table[2] = new inch16(1,8,0.125f);
inch16_table[3] = new inch16(3,16,.1825f);
inch16_table[4] = new inch16(1,4,0.25f);
inch16_table[5] = new inch16(5,16,0.3125f);
inch16_table[6] = new inch16(3,8,0.375f);
inch16_table[7] = new inch16(7,16,0.4375f);
inch16_table[8] = new inch16(1,2,0.5f);
inch16_table[9] = new inch16(9,16,0.5625f);
inch16_table[10] = new inch16(5,8,0.625f);
inch16_table[11] = new inch16(11,16,0.6875f);
inch16_table[12] = new inch16(3,4,0.75f);
inch16_table[13] = new inch16(13,16,0.8125f);
inch16_table[14] = new inch16(7,8,0.875f);
inch16_table[15] = new inch16(15,16,0.93755f);
}
/****************************************************************
//linear searches the inch16 table for the first measurement
// that is GREATER than the decimal measurement; returns
// the inch16 obj if it is there; returns NULL otherwise
// which means rounds to the next inch.
// EXAMPLE inch16_lookup(0.4235) returns 7/16 or {7,16,0.4375}
// EXAMPLE inch16_lookup(0.8894) returns 16/16 or {15,16,0.9.7375}
// EXAMPLE inch16_lookup(0.4567) returns 1/2 or {1,2,0.5}
// EXAMPLE inch16_lookup(0.98765) returns NULL, so you
// must round up to the next whole inch
*********************************************************************/
public inch16 inch16_lookup( double decimalMeasurement)
{
inch16 inch16ObjReturn = null;
for (int iLoop=0; iLoop<16; iLoop++)
{
//System.out.println("inch16_lookup : iLoop = " + iLoop);
if (inch16_table[iLoop].getDecimalAmt()>=decimalMeasurement)
{
inch16ObjReturn = inch16_table[iLoop];
break;
}
}
return(inch16ObjReturn);
}
private void input()
{
Console console = System.console();
System.out.print(" Please input the height in centimeters :>");
String inbuff = console.readLine();
centimeters = Double.parseDouble(inbuff);
//System.out.println(" Input measurement in centimeters = " + centimeters);
}
private void output()
{
System.out.println(" The measurement in centimeters is " + centimeters);
System.out.println(" The measurement in english measure is ");
System.out.print( feet + " feet : " + inches + " ");
if (myInch16 != null)
{
System.out.print( myInch16.getNumerator() + "\\" + myInch16.getDenominator() );
}
System.out.println(" inches");
}
private void convertMetricCentimetersToEnglishMeasures()
{
// first changes centimeters to inches: 1 inch = 2.54 centimeters;
double Inches = centimeters / 2.54;
//throws stores the same result as an integer with no decimals
int iInches = (int) (Math.floor(Inches));
// next changes inches to feet
feet = (int) (iInches / 12);
inches = (int) (iInches % 12); // whole inches
double fractionInch = Inches - iInches; //fraction of the inch
myInch16 = inch16_lookup(fractionInch);
if (myInch16 != null)
{
// found the fraction of the inch by rounding up to the nearest 16th of the inch
}
else
{
feet++;
inches = 0;
}
} // convertMetricCentimetersToEnglishMeasure
public static void main(String args[])
{
EnglishMetricMeasurements X = new EnglishMetricMeasurements();
if (args.length==0) //centimeters not given on the command line
{
X.input(); //prompts the user to input the measurement in centimeters
}
else // measurement in centimeters given on the command line
{
double cm = Double.parseDouble(args[0]);
X.setCentimeters(cm);
}
X.convertMetricCentimetersToEnglishMeasures();
X.output();
}
} //class EnglishMetricMeasurements
Fabay J.
This is not the exact code that i am looking for.
Sir please help me to solve this problem.
this is the possible output.
java programming
Please enter your height(cms):______
Your height is _______cm,s and it is equivalent to __________feet and inches.
Your height is _______cm,s and it is equivalent to __________feet and inches.
Report
08/09/17
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Andy C.
07/21/17