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

Discussion in 'Mac Programming' started by macman2790, Feb 18, 2007.

  1. macrumors 6502a

    macman2790

    Joined:
    Sep 4, 2006
    Location:
    Texas
    #1
    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.
     
  2. macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #2
    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.
     
  3. thread starter macrumors 6502a

    macman2790

    Joined:
    Sep 4, 2006
    Location:
    Texas
    #3
    thanks man, i wish i would've looked over those before....i never do.
     
  4. thread starter macrumors 6502a

    macman2790

    Joined:
    Sep 4, 2006
    Location:
    Texas
    #4
    never mind, should this determine which student gets the scholarship?
    thanks
     
  5. macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #5
    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. ]
     
  6. thread starter macrumors 6502a

    macman2790

    Joined:
    Sep 4, 2006
    Location:
    Texas
    #6
    thanks for the help, i understand the assignment clearly and now i am done.
     
  7. macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #7
    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.
     
  8. macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #8
    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?
     

Share This Page