Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The United Federation of Planets is preparing to make first contact with a new a

ID: 3638926 • Letter: T

Question

The United Federation of Planets is preparing to make first contact with a new alien race, the Bynars.
Very little is known about this species except the following:
• The Bynar language is composed solely of sequences of 1s and 0s.
• If a Bynar’s name contains an odd number of 1s, he is a male; if it contains an even number of 1s,
she is a female.
Diplomacy is critical during first contact. It would be disastrous if a UFP ambassador were to address a
male Bynar as “miss” or a female Bynar as “mister.” Starfleet’s Diplomatic Corps has suggested that
you can solve the problem by writing a Java method for the Universal Translator that will determine
whether a given Bynar is male or female, by name alone.
Fill in the body of the getGender() method. This method takes a single String argument
representing a Bynar name (it only contains ‘1’ and ‘0’ characters). If the name contains an odd number
of 1s, the method returns the String “Male”; otherwise, it returns the String “Female.” Your method
should not print anything.
You may write any additional helper methods that you need for this problem.
fill in the followings:

public static String getGender (String name)
{
// Fill in this method

return null; // CHANGE THIS LINE
}
}

Explanation / Answer

Hi, here is the full getGender method in which I use the static String.charAt(i) method and the % acrry operation over 2 to determine whether a number is odd or even. You can look those up. I made the code as clear as possible and included plenty of comments for each part so you know what's going on. Please take the time to read it, understand it, and test it out a few times. Don't just copy-paste it and expect it to work just like that :) if there's anything missing or unclear, send me a PM and we can look at it again.

I hope it helps, please remember to rate!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote