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

    Default having problem with returning an interface with two method

    HI, I am having problem with return methods in an interface. I was wondering if anyone will be able to let me know what i have to type in an interface since there isn't parameter is illegal.

    //(2) StudentStatisticCalculator.java
    //An interface with two methods:
    //getName(), which returns a String
    //computeStatistic(Student[] students), which returns a double


    public class Student{

    String name;
    double gpa;

    public String getName(){
    return name;
    }

    public double getGPA() {
    return gpa;

    }

    }





    public interface StudentStatisticCalculator{


    public String getName();
    String name=name;


    public double computeStatistic(Student[]student();
    return computestatistic;

    }


    following error:

    StudentStatisticCalculator.java:15: ')' expected
    public double computeStatistic(Student[]student();
    ^
    StudentStatisticCalculator.java:15: illegal start of type
    public double computeStatistic(Student[]student();
    ^
    StudentStatisticCalculator.java:15: <identifier> expected
    public double computeStatistic(Student[]student();
    ^
    StudentStatisticCalculator.java:16: = expected
    return computestatistic;
    ^
    StudentStatisticCalculator.java:16: ';' expected
    return computestatistic;
    ^
    5 errors

  2. #2
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Smile

    Please go through the basics of Interface, things will become clear on its own.

    You are making some very basic mistakes.

  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

    As lovelesh said, these are basic basic mistakes, I suggest you start with
    Trail: Learning the Java Language (The Java™ Tutorials)

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

    Default

    So I was able to fixed up the getName but the other method I have no idea.

    //(2) StudentStatisticCalculator.java
    //An interface with two methods:
    //getName(), which returns a String
    //computeStatistic(Student[] students), which returns a double



    public interface StudentStatisticCalculator{


    public void getName();


    public void computeStatistic(Student[]student());

    }
    }


    StudentStatisticCalculator.java:14: ')' expected
    public void computeStatistic(Student[]student());
    ^
    StudentStatisticCalculator.java:14: illegal start of type
    public void computeStatistic(Student[]student());
    ^
    StudentStatisticCalculator.java:14: <identifier> expected
    public void computeStatistic(Student[]student());
    ^
    StudentStatisticCalculator.java:14: = expected
    public void computeStatistic(Student[]student());
    ^
    StudentStatisticCalculator.java:14: ';' expected
    public void computeStatistic(Student[]student());
    ^
    5 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.


    Where will i be able to look up basic of interface anyway?

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Be careful.

    The comment:

    Java Code:
    //(2) StudentStatisticCalculator.java
    //An interface with two methods:
    //getName(), which returns a String
    //computeStatistic(Student[] [color=blue][b]students[/b][/color]), which returns a [color=red][b]double[/b][/color]

    The code:

    Java Code:
    public [color=red][b]void[/b][/color] computeStatistic(Student[][color=blue][b]student()[/b][/color]);

    These things can be confusing at first - keep your textbooks and notes handy!

Similar Threads

  1. My method keeps returning 0
    By ToolJob in forum New To Java
    Replies: 11
    Last Post: 03-27-2011, 06:22 PM
  2. Returning Value from a method
    By Mirix in forum New To Java
    Replies: 12
    Last Post: 06-01-2010, 10:48 PM
  3. Inherited method returning bad value
    By viking90 in forum New To Java
    Replies: 11
    Last Post: 04-07-2010, 04:53 PM
  4. returning an object from a method
    By bigj in forum New To Java
    Replies: 7
    Last Post: 01-08-2010, 01:39 PM
  5. Need help. Method won't returning proper value..
    By zlwilly in forum New To Java
    Replies: 2
    Last Post: 12-02-2008, 10:44 PM

Posting Permissions

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