Create a Java program(in NetBeans) that proves the following conversions between
ID: 669165 • Letter: C
Question
Create a Java program(in NetBeans) that proves the following conversions between different units.
1. Liters and Gallons: If 1 liter is 0.26 gallon, then
a. How many gallons is 26 liters (for example, double gals = 26 * 0.26)
b. How many gallons is 3.58 liters?
c. How many liters is 4.5 gallons?
When doing these conversions you should at lease use two variables of the appropriate type for the above conversions.
After each conversion print the value to the console. For example, "5 gallons is 18.9271 liters"
2. Kilograms and pounds: If 1 kilogram is 2.2 pounds,
a. How many pounds is 56 kilograms?
b. How many kilograms is 198.23 pounds?
c. How many pounds is 456.0023 kilograms?
When doing these conversions you should at lease use two variables of the appropriate
type for the above conversions. After each conversion print the value to the console. For example, "15 pounds is 6.80389 kilograms".
Explanation / Answer
1.MyClass.java
public class MyClass {
public static void main(String[] args){
double liters,gallons,conv1,conv2,conv3;
conv1= 26*0.26;
conv2=3.58*0.26;
conv3=4.5/0.26;
System.out.println("26 Liters is "+conv1+" Gallons");
System.out.println("3.58 Liters is "+conv2+" Gallons");
System.out.println("4.5 Gallons is "+conv3+" Liters");
}
}
Expected Output :
2.Conver.java
public class Conver {
public static void main(String[] args){
double kilo,pound,conv1,conv2,conv3;
conv1= 56*2.2; //convertion
conv2=198.23/2.2;//convertion 2
conv3=456.0023*2.2;//convertion 3
System.out.println("56 Kilograms is "+conv1+" Pounds");//display function
System.out.println("198.23 Pounds is "+conv2+" Kilograms");//display function
System.out.println("4.5 Kilograms is "+conv3+" Pounds");//display function
}
}
Expected Output :