3 Replies - 8430 Views - Last Post: 15 September 2007 - 11:56 AM Rate Topic: -----

#1 m_milam  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 23
  • Joined: 15-September 07

Converting user inputed feet into meters

Post icon  Posted 15 September 2007 - 10:20 AM

import java.io.*;
 
public class Feet2Meters {
	public static final double feet2meters = 0.305;

	//  Define a static method that converts feet to meters

	public static double convert(double feet)
	{
		return feet * feet2meters;
	}
	
	
	//  Define a main method to test the class
	
	public static void main(String[] args)
	{
		//  initialize a variable called 'feet'
		double feet = 100;
		
		/*
			initialize a variable called 'meters' that holds the
			returning value of the convert() method
		*/ 
		
		double meters = Feet2Meters.convert(feet);  
		
		// output
		System.out.println(feet +" feet is "+ meters +" meters.");
	}
	
}



I have gotten this far with the code and it works. This does not solve my problem. I need to have the user input the feet and then convert it into meters. The code I posted tells you that 100 feet = 30.5 meters. The amount of feet is already embedded in the code. I figure I just need to build off this but I'm not sure where to go from here.

Does this make sense? I am taking this class to learn the language. I am a web designer by trade and have limited programing experience. I hand code my sites and I am fluent in html, xml, actionscript, and css. Java is new to me. Thank you for your help.

milam.matthew@gmail.com

Is This A Good Question/Topic? 0
  • +

Replies To: Converting user inputed feet into meters

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Converting user inputed feet into meters

Posted 15 September 2007 - 11:02 AM

Well I'll give you one way to do this

you need to import java.util.Scanner; for this one
then you do this:

Scanner scan = new Scanner(System.in);
double input = scan.nextDouble();

This post has been edited by PennyBoki: 15 September 2007 - 11:03 AM

Was This Post Helpful? 0
  • +
  • -

#3 m_milam  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 23
  • Joined: 15-September 07

Re: Converting user inputed feet into meters

Posted 15 September 2007 - 11:42 AM

View PostPennyBoki, on 15 Sep, 2007 - 11:02 AM, said:

Well I'll give you one way to do this

you need to import java.util.Scanner; for this one
then you do this:

Scanner scan = new Scanner(System.in);
double input = scan.nextDouble();



Thank you for your response. Not really sure where the bottom two lines of code should be placed. I really am a newbie at this (about a 2 days into it). I have found another source for some information and I think I have everything running proper.

Once again, thank you for taking the time. Assistance and snippets are always the easiest way for me to learn.
Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Converting user inputed feet into meters

Posted 15 September 2007 - 11:56 AM

I gave you that code as an example on how to get a double from the user. I'm glad that you found the solution for your trouble. Spending some quality time in this community can help you a lot. And by quality time I mean, reading snippets and tutorials, as well as other member's problems.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1