Imagine that you have a list of all the genders (as single characters) of the students in your class, in order of their last name. The list will look something like \MFFMMMFFMFMMFFFM" where \M" is Male and \F" is Female. Write a function (below) percentageGenders(string) to accept a string that represents the genders. You are to count all of the \M"'s and \F"'s in the string, and print out the ratio (as a decimal) of the each gender. For example, if the input string were \MFFF," then the function should print something like \There are 0.25 Males, 0.75 Females" (Hint: Better multiply something by 1.0 to make sure that you get °oats not integers.)
What will be an ideal response?
```
/**
* Method to count the number o f males and f emal e s in a s t r i n g
* where male i s coded as M and female i s coded as F
* This method w i l l p r i n t out the pe r c entag e of males and f emal e s
*/
public s tat ic void pr intPercentMaleFemale ( St r ing aSt r ing )
{
int males = 0 ;
int f emal e s =0;
char currChar ;
// loop through c h a r a c t e r s in the s t r i n g
for ( int i = 0 ; i < aSt r ing . l eng th ( ) ; i++)
{
currChar = aSt r ing . charAt ( i ) ;
i f ( currChar == 'M' )
males++;
el se i f ( currChar == 'F ' )
f emal e s++;
}
double t o t a l = males + f emal e s ;
System . out . p r i n t l n ( "Percent f emal e s i s " + f ema l e s / t o t a l +
" pe r c ent males i s " + males / t o t a l ) ;
}
```
You might also like to view...
During code execution, three namespaces can be accessed: ______ , ___________ and ________ .
Fill in the blank(s) with the appropriate word(s).
What is the value in w after line 5 is run?
``` 1 string s, t; 2 s = “Get up and go to school!”; 3 t = “NO!”; 4 int n = s.size(); 5 int w = s.at(3); 6 int x = s.at(12); 7 s += t; 8 cout << s; ``` A. 3 B. t C. space ‘ ‘ D. u
Indicate whether each of statements is valid, refer to the declarations and initializations below. If the statement is valid, indicate what value is displayed or assigned. If the statement is invalid, explain why.
``` double x[8] = {16.0, 12.0, 6.0, 8.0, 2.5, 12.0, 14.0, -54.5}; int j = 5; ``` printf("%.2f\n", x[j] + 1);
If you connect your printer through a Bluetooth connection or ____ port, Windows should automatically detect the new device.
A. parallel B. serial C. USB D. command