Results 1 to 4 of 4
Thread: Problem with interfaces
- 01-25-2011, 11:34 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
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;
}
}
- 01-25-2011, 11:44 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
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).
- 01-26-2011, 12:04 AM #3
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Extending an interface with inheritance : Interface and Abstract Class*«*Language Basics*«*Java
I believe you need to implement the interface:
Also, use code tags when posting code, [code] to open [ /code]Java Code:public class MyClass implements MyInterface
- 01-26-2011, 08:57 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Interfaces
By blug in forum New To JavaReplies: 1Last Post: 11-19-2010, 04:46 PM -
Interfaces
By justin1980 in forum New To JavaReplies: 9Last Post: 02-10-2010, 12:04 PM -
Interfaces
By computerquip in forum New To JavaReplies: 19Last Post: 09-08-2009, 04:58 PM -
interfaces..
By sireesha in forum New To JavaReplies: 5Last Post: 01-16-2008, 05:52 PM -
Interfaces
By imran_khan in forum New To JavaReplies: 5Last Post: 07-30-2007, 08:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks