Results 1 to 10 of 10
  1. #1
    hoangx87 is offline Member
    Join Date
    Mar 2011
    Posts
    44
    Rep Power
    0

    Default having error with implements.

    Okay I just started writing the code and i already got an error. I was wondering what i have to do to fix it.

    Direction:You'll write SumGpa classes that implement the StudentStatisticCacluator interface,
    to find the sum gpa in the student array passed to printStatistic.


    Code:
    public class SumGPA implements StudentStatisticCalculator {




    }


    (3) SumGPA.java:


    error: SumGPA.java:1: SumGPA is not abstract and does not override abstract method print() in StudentStatisticCalculator
    public class SumGPA implements StudentStatisticCalculator {

  2. #2
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default

    Quote Originally Posted by hoangx87 View Post
    Okay I just started writing the code and i already got an error. I was wondering what i have to do to fix it.

    Direction:You'll write SumGpa classes that implement the StudentStatisticCacluator interface,
    to find the sum gpa in the student array passed to printStatistic.


    Code:
    public class SumGPA implements StudentStatisticCalculator {




    }


    (3) SumGPA.java:


    error: SumGPA.java:1: SumGPA is not abstract and does not override abstract method print() in StudentStatisticCalculator
    public class SumGPA implements StudentStatisticCalculator {
    You haven't defined the methods in the StudentStatisticCalculator interface that you implemented.

    Please read up on interfaces.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by Solarsonic View Post
    You haven't defined the methods in the StudentStatisticCalculator interface that you implemented.

    Please read up on interfaces.
    As was recommended in the original poster's other thread from today, a recommendation he seems to have ignored (not responded to). OP, if you don't understand something, ask. Don't just ignore it or ask the same darn question in another thread.

  4. #4
    hoangx87 is offline Member
    Join Date
    Mar 2011
    Posts
    44
    Rep Power
    0

    Default

    thanks fubarable, after reading it from the book, I am still confuse. About the method interface.


    Instruction :You'll write Sum classes that implement the StudentStatisticCacluator interface,
    to find the sumgpa in the student array passed to printStatistic.


    public class SumGPA implements StudentStatisticCalculator {



    public abstract GetSumGpa();
    return gpa;


    }

    Error:

    SumGPA.java:5: invalid method declaration; return type required
    public abstract GetSumGpa();
    ^
    SumGPA.java:6: illegal start of type
    return gpa;
    ^
    SumGPA.java:6: ';' expected
    return gpa;
    ^
    3 errors

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Oh come on. What part of "return type required" do you not understand? All methods have a return type: void, String, Foo etc.

    Who told you to use the keyword "abstract"? An Interface has abstract methods by default. If your class is going to implement an Interface then your class needs to have fully implemented methods that match the signature of the methods in the Interface.

  6. #6
    hoangx87 is offline Member
    Join Date
    Mar 2011
    Posts
    44
    Rep Power
    0

    Default

    junky, im a college student im not too good with java at the moment

  7. #7
    hoangx87 is offline Member
    Join Date
    Mar 2011
    Posts
    44
    Rep Power
    0

    Default

    im still lost reallyy

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    So exercise your brain. It seems to me like so many others starting out, you are just guessing. Very simple. Complete the code below by filling in the dots so it outputs 2. (without hard coding it)
    Java Code:
    interface Incrementer {
        public int addOne(int value);
    }
    
    class MathLab implements Incrementer {
        ....
    
        public static void main(String[] args) {
            MathLab ml = new MathLab();
            System.out.println(....);
        }
    }

  9. #9
    hoangx87 is offline Member
    Join Date
    Mar 2011
    Posts
    44
    Rep Power
    0

    Default

    Well this is what i have for coding:

    public class SumGpa implements StudentStatisticCalculator {

    interface SumGpa {
    public double addOne(double value);
    }

    class SumGpa implements SumGpa {
    return gpa;

    public static void main(String[] args) {
    SumGpa1 sl = new double gpa();
    System.out.println(Gpa);
    }
    }


    HAve the following error:

    SumGPA.java:8: illegal start of type
    return gpa;
    ^
    SumGPA.java:8: ';' expected
    return gpa;
    ^
    SumGPA.java:11: '[' expected
    SumGpa1 sl = new double gpa();
    ^
    SumGPA.java:11: ']' expected
    SumGpa1 sl = new double gpa();
    ^
    SumGPA.java:14: reached end of file while parsing
    }

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

    Default

    You really need to check your textbook, the sun tutorials, or talk to your teacher.

    An interface is sort of an outline. None of the methods in it have a body, when you implement an interface it is your responsibility to make sure every method in the implemented interface is inplemented in this class.

    If you have an interface x with three methods, a, b, and c and then you create a class called y and make it implement x you must define a, b, and c inside of y.

    Don't just post the compiler errors here. Think about them and examine the lines generating them, try to figure it out yourself, it will be a great learning experience. All the compiler messages usually do a good job of explaining the error.

    I want you to read the section in your text book on interfaces, then read the tutorials. Finally, I want you to explain your understanding of them to me.

Similar Threads

  1. subclass that implements
    By speedycerv in forum New To Java
    Replies: 1
    Last Post: 03-30-2011, 01:11 AM
  2. What does IMPLEMENTS mean?
    By nikkka in forum New To Java
    Replies: 3
    Last Post: 03-07-2011, 11:21 AM
  3. Interface and implements
    By Bored2 in forum New To Java
    Replies: 27
    Last Post: 11-10-2010, 01:08 PM
  4. implements
    By danghieu in forum New To Java
    Replies: 1
    Last Post: 04-29-2010, 05:52 PM
  5. HashSet and AbstractSet both Implements Set
    By rkjsohi2 in forum New To Java
    Replies: 1
    Last Post: 08-07-2008, 11:04 AM

Posting Permissions

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