Answer to Question #183597 in Java | JSP | JSF for Tim

Question #183597

Write a Java code that will create a supportive class named, Conversion, which contains

three methods as specified below.


1) Method Name: Gallon2Liter(), Type: value-returning, Parameter: 1 parameter named g of double type, Operation: Return the result of g×3.78541178


2) Method Name: Inc2Cm(), Type: value-returning, Parameter: 1 parameter named i of doubletype, Operation: Return the result of i×2.54


3) Method Name: Pound2Kg(), Type: value-returning, Parameter: 1 parameter named p of double type, Operation: Return the result of p×0.45359237


In the “main” class, create an instance named “c1” of the “Conversion” class.


Use the “c1” instance to access all the three methods, “Gallon2Liter()”, “Inc2Cm()”, and “Pound2Kg()”, to convert the following values.

• 16.75 gallons

• 37.98 inches

• 140.27 pounds



1
Expert's answer
2021-04-22T07:01:49-0400
   public class Coversion{
  
       public double Gallon2Liter(double g) {
           //converting gallon to litres
           return g*3.78541178;
       }
       public double Inc2Cm(double i) {
           //converting inch to cm
           return i*2.54;
       }
       public double Pound2Kg(double p) {
           //converting pound to kg
           return p*0.45359237;
       }

   }


public class Sample {
   public static void main(String[] args) {
       //creating Conversion object
       Coversion c1=new Coversion();
       //calling all method and printing result
       System.out.println("16.75 gallons\t"+c1.Gallon2Liter(16.75)+" litres");
       System.out.println("37.98 inches\t"+c1.Inc2Cm(37.98)+" cm");
       System.out.println("140.27 pounds\t"+c1.Pound2Kg(140.27)+" kg");
   }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog