Handwrite the Measurable interface The Measurable interface

Hand-write the Measurable interface. The Measurable interface contains one method, getMeasure that returns a double. The Measurable interface categorizes all objects that contain a measure of type double. Hand-write the changes required for the Product class from question 1 to implement the Measurable interface. The getMeasure() method of product will return the cost of the product.

Solution

6)public interface Measurable {                                         //creating interface

public double getMeasure(double cost);                            //with one abstract method we need not to specify abstract keyword

}

type above lines and save the file with the name Measurable.java

7)import java.io.*;

import java.util.*;

public class Product implements Measurable                                //implementing interface

{

public double getMeasure(double cost)                                 //implementation of getMeasure method

{

return double;

}

public static void main(String ar[])

{

double cost,cost1;                                                                //declaring double variable

Scanner s=new Scanner(System.in)                                //creating scanner object

cost=s.nextDouble();

Product pr=new Product();                                            //creating present class object

cost1=pr.getMeasure(cost);                                                   //calling method

System.out.println(\"The cost of the product is:\"+cost1);

}

}

 Hand-write the Measurable interface. The Measurable interface contains one method, getMeasure that returns a double. The Measurable interface categorizes all o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site