0

First, this is homework, but no, I'm not asking for anyone to do any code for me. My course start date isn't for another month (it's online), so I can't ask for clarification. I thought I'd see if this method description even makes any sense in the eyes of the community.

I had to create a class AddressBook that contains contact information such as someone's first, middle, and last names, their phones numbers... etc. (The class should really be called AddressBookEntry to make sense).

After creating the class, step 2 was to create a static method with the signature:

public static String compareNames(String name1, String name2)

And the only description of what they want is:

Using the get and set methods, create a comparison method compareNames(name1, name2) that compares the first, middle, and last names of strings name1 and name2. Assume that name1 and name2 follow the following format: “FirstName M. LastName”.

To me, this doesn't make any sense. I've never seen a comparison method return anything other than a boolean or an signed int for inequality comparisons. The only thing I could think of was returning something like the first chunk of the second name that matches the first; but that seems rather arbitrary.

Maybe I'm missing something here though. How should I interpret this question?

The course has a general discussion board that I can read but not (yet) post to. Someone posted the exact same question as me, and someone else replied with a message from the tutor:

It will return a string that contain the result of comparison between name1 and name2.

Turns out it's not a typo; but that "clarification" didn't really help.

6
  • Returning the same type would make sense if the method's description said "return the argument which is larger." Specificity is the key to almost everything in this field, and here it would have let you sanity check the prototype against the intent. A pox on whoever wrote the problem for not doing that.
    – Blrfl
    May 15, 2015 at 4:00
  • Replace String with AddressBook in method signature and requirements.
    – Basilevs
    May 17, 2015 at 17:00
  • @Basilevs Ya, it should be like that. As noted at the end of the question though, the signature is "correct"; they do in fact want a static function taking 2 Strings, and returning a String, even if it's dumb and makes next to no sense. I made an overload that takes 2 AdressBooks and returns a Boolean, then criticized their teaching methods. Hopefully they can't mark me down for that :/ May 17, 2015 at 17:19
  • @Carcigenicate just wondering what did you end up doing? I just stumbled across the same problem and the question is not making any sense to me. Jan 10, 2016 at 21:17
  • @BurninatorDor I wrote up "legit" comparison method that returned a Boolean, then used that to write their BS required method. I also attached a comment critiquing their teaching methods, but you may wish to skip that part. If I can find the assignment, I can pastebin my answer and link to it in a comment. Jan 10, 2016 at 22:04

1 Answer 1

2

The specification is rather vague, but "comparison method" generally means comparing the two arguments, so the result could be "they're equal or not" (as in Object.equals), which means the result type should be bool, or it could be "first is less, equal, or greater than the other", in which case the result type is either int (as in IComparable.compare), or an enum (as Haskell uses).

It's very unlikely that the result type of comparing two values is of the same type, unless the type being compared is already a bool or int.

7
  • That's my point. I really don't understand what they want here. May 14, 2015 at 23:11
  • @Carcigenicate My guess is typo in the requirements, so once you are able to, you should contact them and ask for clarification. May 14, 2015 at 23:12
  • What do you suggest I assume they meant? Returning a boolean makes the most sense, but mistaking a boolean for a String seems like an odd typo. May 14, 2015 at 23:14
  • 3
    I also just realized that the description says to use getters/setters in a static method. I think whoever wrote this question was drunk. May 14, 2015 at 23:18
  • 1
    I already have a bad feeling about this course. May 15, 2015 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.