PDA

View Full Version : Java: not understanding one of my professor's directions, can someone help clarify




macman2790
Feb 19, 2007, 12:30 AM
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
Feb 19, 2007, 12:46 AM
The details are in the lecture notes (http://www.cs.utsa.edu/~javalab/cs1713/lectures/week04.html).

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
Feb 19, 2007, 12:51 AM
The details are in the lecture notes (http://www.cs.utsa.edu/~javalab/cs1713/lectures/week04.html).

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.

macman2790
Feb 19, 2007, 01:11 AM
never mind, should this determine which student gets the scholarship?
thanks

iMeowbot
Feb 19, 2007, 01:24 AM
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
Feb 19, 2007, 03:16 AM
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
Feb 19, 2007, 03:23 AM
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
Feb 19, 2007, 03:35 AM
(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?