Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macman2790

macrumors 6502a
Original poster
Sep 4, 2006
716
1
Texas
im doing a project for my programming class and i can't figure out what this means:(i know what comparable is, his directions just seem very vague)
Part 3
Have Scholar implement Comparable. The comparison is based on the value returned by getScore. Test this by adding code to ScholarTester.

Heres a link to the directions since you probably will need to know more about the program.
http://www.cs.utsa.edu/~javalab/cs1713/projects/project1.html

if anyone needs my code for scholar or scholarTester, please ask.
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
The details are in the lecture notes.

I gather that for the last part you will need to compare the getScore results from each object, and your instructor wants you to use the Comparable interface to do the work.

Things like that do look like nonsense for the toy programs you end up writing in classes, and in a way they are, but the idea is that you'll know how it's done when faced with a "real" programming problem.
 

macman2790

macrumors 6502a
Original poster
Sep 4, 2006
716
1
Texas
The details are in the lecture notes.

I gather that for the last part you will need to compare the getScore results from each object, and your instructor wants you to use the Comparable interface to do the work.

Things like that do look like nonsense for the toy programs you end up writing in classes, and in a way they are, but the idea is that you'll know how it's done when faced with a "real" programming problem.

thanks man, i wish i would've looked over those before....i never do.
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
I'd assume that you will be adding a compareTo() method to your class, as described in the Java documentation. The argument would be of the same type as your getScore(), since that's most likely what you would be comparing here, the getScore() from some other Scholar object against this one.

It looks as though your compareTo() would be very short, perhaps a one liner. Yes, this would be serious overkill in real life when you could just compare the results of the getScore() methods, but the idea is that once you have the method, you can compare the Scholar objects directly without worrying about what methods make one Scholar "better" than another. Again, this exercise is only to get you used to the idea for when more complicated problems come around.

[edit: Sorry about the vague wording, but I'm trying to stick to the spirit of the assignment's instructions, that paragraph at the top has a pretty clear list of who is allowed to help you directly. ]
 

macman2790

macrumors 6502a
Original poster
Sep 4, 2006
716
1
Texas
I'd assume that you will be adding a compareTo() method to your class, as described in the Java documentation. The argument would be of the same type as your getScore(), since that's most likely what you would be comparing here, the getScore() from some other Scholar object against this one.

It looks as though your compareTo() would be very short, perhaps a one liner. Yes, this would be serious overkill in real life when you could just compare the results of the getScore() methods, but the idea is that once you have the method, you can compare the Scholar objects directly without worrying about what methods make one Scholar "better" than another. Again, this exercise is only to get you used to the idea for when more complicated problems come around.

[edit: Sorry about the vague wording, but I'm trying to stick to the spirit of the assignment's instructions, that paragraph at the top has a pretty clear list of who is allowed to help you directly. ]

thanks for the help, i understand the assignment clearly and now i am done.
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
It looks as though your compareTo() would be very short, perhaps a one liner. Yes, this would be serious overkill in real life when you could just compare the results of the getScore() methods, but the idea is that once you have the method, you can compare the Scholar objects directly without worrying about what methods make one Scholar "better" than another. Again, this exercise is only to get you used to the idea for when more complicated problems come around.

The reason for using the Comparable interface is because it's a standard. You could write a sort method using Comparable, and it would instantly be able to sort any collection of objects that implemented the interface.

Interfaces are emphasized in order to write polymorphic code -- code that can operate on many different data types without having to be re-written or modified.

Hope this makes sense...I wouldn't want you to think that using Comparable in this example is silly or overkill. Understanding this design pattern makes you a much more efficient developer.
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
(a striking example of an utter failure to read)
What parts of "the idea is that you'll know how it's done when faced with a 'real' programming problem" and "this exercise is only to get you used to the idea for when more complicated problems come around" didn't you undertand?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.