DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: LengthConverter

  1. #1
    Join Date
    Aug 2005


    the compiler is saying that in line 35 "double cannot be dereferenced" in "measurement = TextIO getDouble()", its saying the same about "units = TextIO.getlnWorld();"

    public class LengthConverter {

    /* This program will convert measurements expressed in inches,
    feet, yards, or miles into each of the possible units of
    measure. The measurement is input by the user, followed by
    the unit of measure. For example: "17 feet", "1 inch",
    "2.73 mi". Abbreviated in, ft, yd, and mi are accepted.
    The program will continue to read and convert measurements
    until the user enters an input of 0.

    public static void main(String[] args) {

    double measurement; // Numerical measurement, input by user.
    String units; // The unit of measure for the input, also
    // specified by the user.

    double inches, feet, yards, miles; // Measurement expressed in
    // each possible unit of
    // meaure.

    double TextIO; // prints the conversion of the measurements

    System.out.println("Enter measurements in inches, feet, yards, or miles.");
    System.out.println("For example: 1 inch 17 feet 2.73 miles");
    System.out.println("You can use abbreviations: in ft yd mi");
    System.out.println("I will convert your input into the other units of measure.");

    while (true) {

    /* Get the user's input, and convert units to lower case. */

    System.out.println("Enter your measurement, or 0 to end: ");
    measurement = TextIO.getDouble();
    if (measurement == 0)
    break; // terminate the while loop
    units = TextIO.getlnWorld();
    units = units.toLowerCase();

    /* Convert the input measurement to inches. */

    if (units.equals("inch") || units.equals("inches") || units.equals("in"))

    inches = measurement;

    else if (units.equals("foot") || units.equals("feet") || units.equals("ft"))

    inches = measurement * 12;

    else if (units.equals("yard") || units.equals("yards") || units.equals("yd"))

    inches = measurement * 36;

    else if (units.equals("mile") || units.equals("miles") || units.equals("mi"))

    inches = measurement * 12 * 5280;

    else {
    System.out.println("Sorry, but i don't understand \"" + units + "\".");

    continue; // back to start of while loop

    /* Convert measurement in inches to feet, yards, and miles. */

    feet = inches / 12;
    yards = inches / 36;
    miles = inches / (12*5280);

    /* Output measurement in terms of each unit of measure. */

    System.out.println("That's equivalent to:");
    System.out.println(" inches");
    System.out.println(" feet");
    System.out.println(" yards");
    System.out.println(" miles");

    } // end while

    System.out.println("OK! Bye for now.");

    } // end main()

    } // end class LengthConverter

  2. #2
    Join Date
    Aug 2005
    You cannot call methods on primitives. TEXTIO is declared as a double. A double is a primitive. So you cannot do that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.