Question

Check if the genders are the same for the two players, and if they are, return...

Check if the genders are the same for the two players, and if they are, return a value based on their difference in height. If they are not the same gender, you should return either 1 if other is female (and this is male) and -1 otherwise

should be like this:

public int compareTo(VolleyPlayer other){

        if (other.female != female){

                // return a positive value if other is female and this is male

                // return negative value otherwise

        } else {          

            // return one height minus the other such that you sort from highest to lowest

        }

what am i doing wrong?

if(other.female !=female){
return 1;
}
if(!other.female != !female){
return -1;
}
return other.height - height;
  

    }

it does not give correct result.

It mixes the females and males, i want first all females and them males ( after height)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

You can do one thing, let the values be mixed, and then you can apply sorting algorithm to sort it in an ascending order, as F comes first when compared to M.

if(other.female !=female){
   return 1;
  }
if(!other.female != !female){
   return -1;
}
return other.height - height;
 }

To sort strings, here is the pseudo code:

void sortString(string &str) 
{ 
   sort(str.begin(), str.end()); 
   cout << str; 
} 

This is just for your reference, if you would like me to write the entire program, let me know.

And kindly upvote as an appreciation

Happy Learning.

Add a comment
Know the answer?
Add Answer to:
Check if the genders are the same for the two players, and if they are, return...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Do women feel differently from men when it comes to tax rates? One question on a...

    Do women feel differently from men when it comes to tax rates? One question on a survey of randomly selected adults asked, "What percent of income do you believe individuals should pay in income tax?" Complete parts a) through c). Click the icon to view the survey results. a) Draw side-by-side boxplots of tax rates by gender. Choose the correct graph below. Survey Results OA. ОВ. A 10 20 30 40 10 20 30 40 M Oc OD 40 40...

  • Question 27 3 pts Imagine that you regressed the earnings of individuals on a constant, a...

    Question 27 3 pts Imagine that you regressed the earnings of individuals on a constant, a binary variable ("Male") which takes on the value of 1 for males and is o otherwise, and another binary variable ("Female") which takes on the value of 1 for female and is o otherwise. Because females typically earn less than males, you would expect: autocorrelation or serial correlation to be a serious problem. the estimated coefficient for Male to have a positive sign, and...

  • Also what is the P value and do I reject the hypothesis v Do women feel...

    Also what is the P value and do I reject the hypothesis v Do women feel differently from men when it comes to tax rates? One question on a survey of randomly selected adults asked, "What percent of income do you believe individuals should pay in income tax?" Complete parts a) through c). B Click the icon to view the survey results. CYC. Each sample size is small relative to the size of its population. LYD. Each sample is obtained...

  • Question 4 5 points Save Answer Researchers wondered whether the size of a person's brain was rel...

    answer that i can understand well please Question 4 5 points Save Answer Researchers wondered whether the size of a person's brain was related to the individual's mental capacity They selected a sample of right-handed Anglo introdu psychology students who had Scholastic Aptitude Test scores higher than 1350. The subjects were administered the Wechsler Adult Intelligence Scale-Revised to obtain their IQ scores. The MRI scans, performed at the same facility, consisted of 18 horizontal MR images. The comp of the...

  • I wrote code in C++ that takes a text file containing information on different football players...

    I wrote code in C++ that takes a text file containing information on different football players and their combine results, stores those players as a vector of objects of the class, and prints out those objects. Finally, I wrote a function that calculates the average weight of the players. MAIN.CPP: #include "Combine.h" #include using namespace std; // main is a global function // main is a global function int main() { // This is a line comment //cout << "Hello,...

  • Having trouble with the do while/while loop and the switch statement. I got some of the...

    Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...

  • Consider the following least squares specification between test scores (m and the student-teacher ratio: Ý 607.8...

    Consider the following least squares specification between test scores (m and the student-teacher ratio: Ý 607.8 + 5.32 in gncome). According to this equation, a 1% noease income is assocated with an increase in test scores of 0 607.8 points O B. 5.32 points ° C. 0.0532 points O D. 53.2 points Reset Selection Mark for Review What's This? Part 12 of 18-0 Question 12 of 18 1.0 Poir Consider the population regression of log earnings Y where Y- In(Eamings...

  • he following data comes from “The Impact of AIDS on Gender Differences in Willingness to Engage...

    he following data comes from “The Impact of AIDS on Gender Differences in Willingness to Engage in Casual Sex” by Russell Clark, Journal of Applied Social Psychology, Vol. 20, No.9, pp.771-782. In this study researchers were interested in gender differences in willingness to engage in casual sex. Both males and females were approached by opposite sex confederates and asked one of the three questions: “I have been noticing you around campus. I find you to be very attractive.” Then the...

  • 11. 8. Consider the following pay-off matrix for social and solitary Solitary Social individuals. Social individuals...

    11. 8. Consider the following pay-off matrix for social and solitary Solitary Social individuals. Social individuals clump with any other individual Solitary 69 around, regardless of whether the other individual is social or not. Social 57 The numbers represent the payoff to the focal individual who is defined by the row label. What strategy would a rational player adopt? a. Social b. A rational player should choose to be social only some of the time. C. A rational player should...

  • IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse, and the message. I will have 6 rows in th...

    IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse, and the message. I will have 6 rows in the table, and 4 columns, followed by  averages. Calculate the ideal age of a spouse. Enter either m or f from the keyboard in lower case. You may use string data for the gender. Convert the gender to upper case Enter an age from the keyboard, probably an integer You will need prompts telling the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT