Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Networking TechnologyRSS Feeds

Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds()

Posted By: Daniel Evans     Category: Java     Views: 4482

Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds(). Create one class which implements the above functions.

Code for Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds() in Java

interface Convert_Measures
{
   double inchestomm(double inches);
   double hptowatts(double hp);
   double wattstohp(double watts);
   double poundstogm(double pounds);
   double gmtopounds(double gm);
}


class Cnvrt_Msrs implements Convert_Measures
{
   publicdouble inchestomm(double inches)
   {
       double mm;
       mm = 2.5 * 10 * inches;
       System.out.println("There are " + mm + " mm in " + inches + " inches");
       return mm;
   }

   publicdouble hptowatts(double hp)
   {
       double watts;
       watts = 746 * hp;
       System.out.println("There are " + watts + " watts in " + hp + " hp");
       return watts;
   }

   publicdouble wattstohp(double watts)
   {
       double hp;
       hp = (1/746) * watts;
       System.out.println("There are " + hp + " hp in " + watts + " watts");
       return hp;
   }

   publicdouble poundstogm(double pounds)
   {
       double gm;
       gm = 453.59 * pounds;
       System.out.println("There are " + gm + " gm in " + pounds + " pounds");
       return gm;
   }

   publicdouble gmtopounds(double gm)
   {
       double pounds;
       pounds = (1/453.59) * gm;
       System.out.println("There are " + pounds + " pounds in " + gm + " gm");
       return pounds;
   }
}

class Conversions
{
   publicstaticvoid main(String args[])
   {
       Cnvrt_Msrs CM = new Cnvrt_Msrs();
       double mm;
       double pounds;
       double watts;
       mm = CM.inchestomm(2);
       pounds = CM.gmtopounds(4.3);
       watts = CM.hptowatts(3);
   }
}


/*
Output

There are 50.0 mm in 2.0 inches
There are 0.00947992680614652 pounds in 4.3 gm
There are 2238.0 watts in 3.0 hp

*/
  
Share: 



Daniel Evans
Daniel Evans author of Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds() is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!