Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

method for converting distance

$
0
0
im having trouble figuring out the best way to sold the following problem:
write a private void method called "Normalize( )", which keeps the distance the same but converts the fields so that feet is less than 5280 and inches is less than 12. (There are 5280 feet in a mile, and 12 inches in a foot). So for example, if miles = 3, feet = 10600, inches = 41, this would normalize to miles = 5, feet = 43, inches = 5.

here is what im coming up with. any help would be greatly appreciated.

private void normalize(int dist,int i, int f, int m)
	{
			//convert all to inches
			
			i1 = ((m*63360)+(f*12)+i)
			
			// normalizing using inches
			
			m = i1 / 63360; //gets miles from inches
			i1 = i1 % 63360; //gets remainder
			f = i1 / 12; // gets feet from inches
			i1 = i1 % 12; // gets remainder
			i = i1;
		
			System.out.print(m + " " + f + " " + i);
	
			//possible solution using a loop???
			
			for(i = 0; i < 12; i++)
			f++;

			for(f=0; f < 5280; f++)
			m++;
		
	}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>