Click here to Skip to main content
15,916,432 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more:
Hi
I am a newbie in Java programming, I have and assignment from school I need some help with.

So I can only use, for loops, while loops or do loops to solve the problem.

I have a file containing this:
Erik Rita Tanner Jillyn Curtis Stefanie Ben

And the result could be 4 boys, 3 girls.

How do i get it to count the boys and girls name?
This is what I have so far:

Java
public class EX6_1
{

   public static void main(String[] args) throws FileNotFoundException
   {
      
      Scanner input = new Scanner(new File("names.rtf"));
      boyGirl(input);      
      
   }
   public static void boyGirl(Scanner input)
   {
      
      while(input.hasNextLine())
      {
         String name = input.next();
         int number = input.nextInt();
         int boys =0;
         int girls =0;
         
                          
      }         
   }


}
Posted
Comments
Nelek 9-Mar-14 11:06am    
And who determines if a name s girl or boy name? i.e. "Alex", "Jo" and many others... they can be used for both, girls and boys. And with dummy names as: "asdhfmnasf -,nasf" ???

You should have something to compare with
tina_overgaard 9-Mar-14 11:34am    
I know that each other is a girls name
Sergey Alexandrovich Kryukov 9-Mar-14 12:27pm    
Even now the "problem" is not fully formulated. No, it is impossible to infer gender from a name. So, what else is known?
—SA
Krunal Rohit 9-Mar-14 11:54am    
How is it working anyway ??

-KR

1 solution

If the names are alternating, the solution is: if the name in the list N is even, there are N/2 boys, as many as girls.
If it is odd, there are two possibilities: N/2 boys and N/2 + 1 girls, or visa versa; to know which of the two possibilities is an answer, it is required to know the gender of at least one name. For example, the gender of the first or last name will be the gender with N/2 + 1 representatives.

And of course, it is impossible to infer gender from a name.

The problem is unrelated to programming. In some cultures, a name of a person allows to infer the gender, because the names are segregated (or classified) by gender, or, more typically, have different male and female form. But even in the same country, the population include representatives of different cultures, and, for different cultures, this is not a rule. Moreover, some typical male names in one culture are typically used for female names in another one.
There should be some additional information which you never mentioned. I suggest we close this "problem" at this point. If you failed to mention the key condition (alternating of the name) in first place, how anyone can trust your ability to formulate problems? There can be something else you failed to mention, and then something else you formulated incorrectly, and so on…

—SA
 
Share this answer
 
v2
Comments
Maciej Los 9-Mar-14 15:16pm    
And i would say: the recognition of gender ("extracted" from name) depends on language specifics. In Poland most women names ends with "a", for example: Anna, Aneta, Beata, Celina, Daria, Ewelina, Fryderyka, Grażyna, Halina, Irena, Joanna, Katarzyna, ... Zenobia.
5!
Sergey Alexandrovich Kryukov 9-Mar-14 15:58pm    
When I said "in some cultures", I meant Poland. But only in some...
—SA
Maciej Los 9-Mar-14 16:11pm    
Joker ;)
Maciej Los 9-Mar-14 16:18pm    
Continuing our discussion... Gibberish = nonsense.
Sergey Alexandrovich Kryukov 9-Mar-14 20:00pm    
No, no, "gibberish" and "nonsense" are very, very different concepts:
http://en.wikipedia.org/wiki/Nonsense,
http://en.wikipedia.org/wiki/Gibberish.

Gibberish is certainly nonsense, but nonsense does not have to be gibberish, which includes "speech sounds that are not actual words,[1] or forms such as language games or highly specialized jargon that seems non-sensical to outsiders". So, gibberish is more specialized form of nonsense closer to somewhat different concept "word salad": http://en.wikipedia.org/wiki/Word_salad.

Also, people talking or writing this way could be easily suspected of schizophasia: http://en.wikipedia.org/wiki/Schizophasia, which is often referred to in the Web culture (especially in sub-cultures). In fact, it's usually more reasonable to assume that schizophasia is only an impression resulted from illiteracy and sloppiness. For many people not having a command in some matter, its pretty natural to "shoot from hips", trying to throw out "clever-looking" words instead of something real. This is very characteristic for some of questions (and even some answers, less often) on this forum.

Funny expression is Russian "ерунда" (popular enough in everyday speech), which originated from the word "gerund" (grammar form in Latin, English, and so on). It was created by students of the time where in Latin language was a must in high schools. This grammar form seemed to be so unnatural, difficult to understand and incomprehensible that people created this word to express some kind of "nonsense". These days, this word is much more popular than literately spoken word "nonsense" ("бессмыслица") :-).

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900