• Post Reply Bookmark Topic Watch Topic
  • New Topic

LengthConverter  RSS feed

 
kofi ofei
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
was wondering if i could get any help compiling this progam. thanks!!!



[JAM -- Edited to add [CODE] and [/CODE] tags]
[ June 16, 2005: Message edited by: Joel McNary ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java In General (Beginner) Forum.

This forum is for J2ME, Mobile Device questions. Basically, MIDlets.

Mark
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a close look at your compiler errors. They are usually very helpful (but occasionally confusing.) The first ones I saw didn't like a backslash followed by a space. I took out the space and then got a couple about System.out.println not understanding the arguments you gave. I'm guessing you meant the 15 to right justify in 15 characters? You'll have to write your own little method to do that. Just take the 15 out for a minute and see if the rest works ok.
 
kofi ofei
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
kofi ofei
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have made the changes you have suggested. i still have three errors in this program. it is complaining about my variable "TextIO" and my other variable "measurement"


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.

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");
System.out.println("of measure.");
System.out.println();

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 (meaurement == 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();
System.out.println("That's equivalent to:");
System.out.println(inches);
System.out.println(" inches");
System.out.println(feet);
System.out.println(" feet");
System.out.println(yards);
System.out.println(" yards");
System.out.println(miles);
System.out.println(" miles");
System.out.println();

} // end while

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

} // end main()

} // end class LengthConverter
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If TextIO is a variable, it has not been declared anywhere. You need to declare it before you can use it.

If TextIO is a class, provided by someone, you need to import it, if it is not in the same package. Can't really help you much with this case, without more information.

Henry
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the EXACT error messages. Summarizing typically loses critical information that we need to help answer your questions. Remember that copy-and-paste is your friend!

Layne
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would also help a lot if you used the "code" tags... there are a bunch of nifty button just below the "add reply" button that will show you what they look like. then paste your code between them - this will preserve the formatting and make your code much easier to read.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!