Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

feet to meters using arrays and methods

962826Oct 16 2012 — edited Oct 17 2012
The assignment is to create two arrays with double data types: 1) 1-10 for feet to meters conversion and 2) 20-30 for meters to feet conversion.

Then to write a program that uses two methods: 1) public static double footToMeter (double foot) and 2) public static double meterToFoot (double meter) within one class file outside of the main method.

The formulas for the conversions are:
Feet to Meters = 0.305 * foot (1 ft = 0.3048 meters ) -- 1.0 feet = 0.305 meters
Meters to Feet = Meters * 3.280839895 -- 20.0 Meters = 65.574 Feet

I am having coding paralysis. As a novice programmer, this may just be outside of my knowledge. I need help and a little explanation. I created the arrays. Here is my outline for solving this:

1) put feet in array

2) put meters in array

3) write method feet to meters

4) write method meters to feet

5) take feet in array and initialize feet to meters method

6) take meters in array and initialize meters to feet array

7) Display results in a table
public class FeetMeters {
	//Create feet array
	double[] feet = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
				  
	//Create meters array
	double[] meters = {20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
	
	
	/** Convert from Feet to Meters **/
	public static double footToMeter(double foot){
		return (0.305*foot);	
	}
		
	/** Convert from Meters to Feet **/
	public static double meterToFoot(double meter){
		return (3.280839895*meter);
	}

	public static void main (String[] args) {
		
		
		
		
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 14 2012
Added on Oct 16 2012
16 comments
1,417 views