professor's instructions are vague can someone clarify please?

i'm not having much trouble with this project until i stumbled upon part 3. His instructions seem vague to me. Here is the project url so you guys can read a bit to find out a little more to understand my program. http://www.cs.utsa.edu/~javalab/cs1713/projects/project1.html

it's a compareTo() method, heres mine:publicint compareTo(Object obj){

Scholar otherObj = (Scholar)obj;

double result = getScore() - otherObj.getScore();

if (result > 0)

return 1;

elseif (result < 0)

return -1;

return 0;

}

here is what i'm printing out in the main class:

System.out.println(student1.compareTo(student2));

it just returns a 1 or -1, which makes sense since that's what i am returning.

But why is this even needed, and am i missing something, and what should i be printing out if there is something i'm missing.

thanks in advance.

[1275 byte] By [kevin123a] at [2007-11-26 18:52:34]
# 1
Read this: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Comparable.htmlIt explains what it's there for and tells you what the method has to do. Including what to printing (namely, nothing).
CeciNEstPasUnProgrammeura at 2007-7-9 6:26:36 > top of Java-index,Java Essentials,Java Programming...
# 2
> But why is this even neededIt follows from the way the assignment has been defined. Look up 'Comparable' for more information.And there's nothing 'vague' about the requirements that have been stated.
ejpa at 2007-7-9 6:26:36 > top of Java-index,Java Essentials,Java Programming...
# 3
should my return statements be likereturn obj + " scored higher than " + otherObj;return otherObj + " scored higher than " + obj
kevin123a at 2007-7-9 6:26:36 > top of Java-index,Java Essentials,Java Programming...
# 4
Does that compile? Do you have a reason to believe that's what Comparable.compareTo() should return?
ejpa at 2007-7-9 6:26:36 > top of Java-index,Java Essentials,Java Programming...
# 5
> should my return statements be likeDo the API docs say so?
CeciNEstPasUnProgrammeura at 2007-7-9 6:26:36 > top of Java-index,Java Essentials,Java Programming...
# 6
never mind, should i do an if else on my scholartester class and say that "student 1 got a higher score than student 2". lol, i wasnt paying attention to the document. that was funny.
kevin123a at 2007-7-9 6:26:36 > top of Java-index,Java Essentials,Java Programming...
# 7
> never mind, should i do an if else on my> scholartester class No. It's your Scholar class that implements comparable.>and say that "student 1 got a higher score than student 2"Who said you should?
CeciNEstPasUnProgrammeura at 2007-7-9 6:26:36 > top of Java-index,Java Essentials,Java Programming...
# 8

so am i using it as he wants in the scholar class?

public int compareTo(Object obj){

Scholar otherObj = (Scholar)obj;

double result = getScore() - otherObj.getScore();

if (result > 0)

return 1;

else if (result < 0)

return -1;

return 0;

}

and what should i be returning in scholarTester?

Message was edited by:

kevin123

kevin123a at 2007-7-9 6:26:36 > top of Java-index,Java Essentials,Java Programming...
# 9

You have to implement the Comparable interface and have the method(s) concerned return plausible values. The compiler will tell you when you've done part of that, but only your common sense can tell you the rest. Ditto your test program.

Unless you want me to get the marks for the assignment ...

ejpa at 2007-7-9 6:26:36 > top of Java-index,Java Essentials,Java Programming...
# 10
i got it, thanks for the help.
kevin123a at 2007-7-9 6:26:37 > top of Java-index,Java Essentials,Java Programming...