Results 1 to 4 of 4
  1. #1
    adamgsell is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default Problem with interfaces

    Hello, I'm having trouble implementing a class that uses a interface (known as Measurable).

    Any help would be greatly appreciated as I am highly confused

    My errors are:

    cannot find symbol class Measurable
    operator + cannot be applied to double, Measurable.getMeasure
    incompatible types
    and double cannot be dereferenced

    my code is

    public class DataSet
    {
    private double sum;
    private int count;
    private double maximum;


    public DataSet()
    {
    sum=0;
    count=0;
    maximum=0;
    }
    public void add(Measurable x)
    {
    count++;
    sum = sum + x.getMeasure();
    if (count == 1 || x.getMeasure()>maximum.getMeasure()) maximum=x;
    }
    public double getSum()
    {
    return sum;
    }
    public int getCount()
    {
    return count;
    }
    public double getMaximum()
    {
    return maximum;
    }
    public double getAverage()
    {
    return sum/count;
    }

    }

  2. #2
    adamgsell is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default Fixed some stuff

    actually scratch what I said earlier. New code with only one error cannot find symbol class Measurable. Any reason it can't find the class? (Measurable is the interface).

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Extending an interface with inheritance : Interface and Abstract Class**Language Basics**Java

    I believe you need to implement the interface:
    Java Code:
    public class MyClass implements MyInterface
    Also, use code tags when posting code, [code] to open [ /code]

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    Where is Measureable?
    Is it in a package?
    How are you compiling this?

Similar Threads

  1. Interfaces
    By blug in forum New To Java
    Replies: 1
    Last Post: 11-19-2010, 04:46 PM
  2. Interfaces
    By justin1980 in forum New To Java
    Replies: 9
    Last Post: 02-10-2010, 12:04 PM
  3. Interfaces
    By computerquip in forum New To Java
    Replies: 19
    Last Post: 09-08-2009, 04:58 PM
  4. interfaces..
    By sireesha in forum New To Java
    Replies: 5
    Last Post: 01-16-2008, 05:52 PM
  5. Interfaces
    By imran_khan in forum New To Java
    Replies: 5
    Last Post: 07-30-2007, 08:11 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •