TechArena Community kilometers per liter to mpg program.

#1
31-07-2009
 Member Join Date: Jul 2009 Posts: 1,113
kilometers per liter to mpg program.

Hi,

I am making a program in java to convert the kilometers per liter (kpl) to miles per gallon (mpg).
I need some help with this. Should I use Swing component for GUI?

What should be the correct way to present the page & to show reverse conversion too.

Visala28
#2
31-07-2009
 Member Join Date: May 2008 Posts: 32
Re: kilometers per liter to mpg program.

1 KPL = 2.84 MPG (imperial)
1 MPG = 0.35 KPL

Now u can code your program both the ways. Use swing for better representation or you can just do it with simple html too. or applet or also can be done with JSP for saving purpose.
#3
31-07-2009
 Member Join Date: May 2008 Posts: 20
Re: kilometers per liter to mpg program.

To convert kpl to mpg multiply your kilometers per liter(kpl) with 2.353
Eg. 10 kpl = 2.353 * 10 = 23.53 mpg
#4
31-07-2009
 Member Join Date: May 2008 Posts: 22
Re: kilometers per liter to mpg program.

Kilometers per Liter to Miles per Gallon

Kilometers per liter : The distance traveled by a vehicle which is running on gasoline or diesel fuel in a kilometer.

Miles per Gallon: The distance traveled by a vehicle which is running on gasoline or diesel fuel in a mile.

mpg = kmpl * Conversion_factor.
Value of the conversion factor is 2.352145 which is constant

code:

Code:
```<html>
<title>ConversionTable of Kilometers perLiter and Miles per Gallon </title>
<body>
<FONT SIZE="6" COLOR="#CC99FF">ConversionTable of Kilometers
perLiter and Miles per Gallon</FONT>
<table border="1" bgcolor="#CCCCFF">
<tr><td><b>Kilometers per Liter</b></td><td><b>Miles per Gallon</b></td><tr>
<%

double kmpl=0.0;
double mpg=0.0;
final double CONVERSION_FACTOR = 2.352145;

for ( kmpl = 5; kmpl < 25;kmpl++){

mpg = kmpl * CONVERSION_FACTOR;
%>
<tr>
<td><%=kmpl%>
</td>

<td><%=mpg%>
</td>
</tr>
<%
}
%>

</table>

</body>
</html>```

 Tags: