Question

write a java code, and add methods to -Compute the average age of all female students....

write a java code, and add methods to

-Compute the average age of all female students.

-Compute the least amount of credits completed among males.

Store the three arrays in the demo file.

Print the results within the demo file.

String []gender ={"F", "F", "M", "F", "F", "M", "M", "M", "M", "F", "M", "F", "M", "F", "F", "M", "M", "F", "M", "F"};

int []age = {18, 19, 19, 21, 20, 18, 24, 19, 21, 21, 21, 23, 20, 20, 19, 18, 19, 21, 20, 22};

int []credits_completed = {45, 12, 54, 23, 26, 33,18, 16, 28, 34, 36, 33, 49, 58, 51, 40, 38, 48, 56, 10};

Homework Answers

Answer #1

Note: - The screenshot of code and output is attached for your refrence .

Demo.java

import java.util.ArrayList;
import java.util.Collections;

public class Demo 
{
        
        //main method 
                public static void main(String[] args) {
                        
                        
                        //array defined for gender , age , credit completed
                        String []gender ={"F", "F", "M", "F", "F", "M", "M", "M", "M", "F", "M", "F", "M", "F", "F", "M", "M", "F", "M", "F"};

                        int []age = {18, 19, 19, 21, 20, 18, 24, 19, 21, 21, 21, 23, 20, 20, 19, 18, 19, 21, 20, 22};

                        int []credits_completed = {45, 12, 54, 23, 26, 33,18, 16, 28, 34, 36, 33, 49, 58, 51, 40, 38, 48, 56, 10};
                        
                        
                        
                        //list to store  male credit completed and age of females 
                ArrayList<Integer> male = new ArrayList<Integer>(); 
                ArrayList<Integer> female = new ArrayList<Integer>(); 

                        
                        for(int i=0 ; i < gender.length ; i++)
                        {
                                if(gender[i].equals("F"))
                                {
                                        female.add(age[i]);
                                }
                                else
                                {
                                        male.add(credits_completed[i]);

                                }
                        }
                        Collections.sort(male);
                        Collections.sort(female);
                        
                                System.out.println("Average age of all female students -- "+averageAgeFemale(female));
                                System.out.println("Least amount of credits completed among males -- "+leastCreditByMale(male));
                        
                }
                
                
                
                
                //method to calculate least amount of credits completed among males.
                private static int leastCreditByMale(ArrayList<Integer> male) {
                        
                        return male.get(0);
                }

                
                
                
                //Method to Calculate average age of all female students.
                private static float averageAgeFemale(ArrayList<Integer> female) {
                                
                        float sum =0;
                        for (Integer integer : female) 
                        {
                                sum = sum + integer;
                        }
                        return sum/female.size();
                        
                }
}

Demo.java -

Output-

Know the answer?
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
Similar Questions
Credit Score Age Income Residence Gender Louise 546 20 $484 1 Female Danielle 601 29 $936...
Credit Score Age Income Residence Gender Louise 546 20 $484 1 Female Danielle 601 29 $936 18 Female Mohan 610 36 $953 13 Male Roger 829 65 $1,549 19 Male Brad 643 36 $1,169 12 Male John 652 34 $1,591 8 Male Karim 787 62 $1,522 11 Male Jasmine 669 40 $1,202 9 Female Emily 775 55 $1,873 5 Female Donna 688 49 $1,185 11 Female Monique 740 54 $1,346 3 Female Fred 690 44 $1,521 17 Male Maria 710...
(Java) Below are three arrays each containing 50 values. Store all three arrays in the main...
(Java) Below are three arrays each containing 50 values. Store all three arrays in the main method. Write an object to transfer the three arrays. int []num_wallet = {4, 3, 4, 2, 4, 6, 7, 2, 6, 1, 6, 1,1,5, 1, 4, 5, 4, 3, 2, 1, 2, 3, 3, 2, 3, 6, 5, 0, 0, 1, 3, 1, 5, 1, 0, 3, 0, 2, 1, 2, 3, 4, 1, 2, 0, 0, 1, 4, 1, 5}; int []dollar[] =...
A person’s muscle mass is expected to be associated with age. Some people also thought exercise...
A person’s muscle mass is expected to be associated with age. Some people also thought exercise time would be associated with the muscle mass. To explore the potential relationships between muscle mass and age, muscle mass and exercise time, a nutritionist randomly selected 20 women from a population of women with age ranging from 40 to 80 years old, and measured their muscle mass (a score without unit) and exercise time (hours per month) Patient Age MuscleMass ExcerciseTime 1 43...
You should make up a transaction file with at least 3 records of students. Write a...
You should make up a transaction file with at least 3 records of students. Write a main program that creates a collection of students. Your transaction file contains a set of information about students. Your program should contain four classes: StudentProfile, Person, Student, and Course. StudentCollection has the following attributes:             vector<StudentProfile>           StCollection; StudentProfile class has the following attributes: Person                         PersonalInfo Student            StdInfo Person class has the following attributes: long                 SSN string               Fname string              ...
MALE :Student # Gender Height Shoe Age Hand 1 M 67 10 19 R 2 M...
MALE :Student # Gender Height Shoe Age Hand 1 M 67 10 19 R 2 M 74 12 17 R 3 M 72 11.5 19 R 4 M 69 10 35 R 5 M 66 9 18 R 6 M 71 10.5 17 R 7 M 72 10.5 17 R 8 M 66 10 20 R 9 M 67 10 18 R 10 M 71 10.5 24 R 11 M 66 10 21 R 12 M 71 10.5 18 R...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
Sex (1 = Males, 2 = Females); Size_car (1 = Small, 2 = Medium, 3 =...
Sex (1 = Males, 2 = Females); Size_car (1 = Small, 2 = Medium, 3 = Large). Data ID   AGE   SEX   SIZE_CAR 1   18   1   2 2   28   1   2 3   44   1   3 4   20   2   2 5   39   2   2 6   53   2   3 7   28   1   1 8   18   1   1 9   24   2   1 10   21   1   2 11   35   1   3 12   38   1   3 13   22   1   1 14   29   1   2 15   63  ...
fl_student_survey (chapter3)----- Check if any association between Gender and abortion legalize. Summarize your results using relevant...
fl_student_survey (chapter3)----- Check if any association between Gender and abortion legalize. Summarize your results using relevant graphs and outputs/tables. subject gender abortion_legalize 1 m n 2 f y 3 f y 4 f y 5 m y 6 m y 7 m y 8 f y 9 m y 10 m n 11 m n 12 f y 13 m y 14 m y 15 f y 16 f y 17 f n 18 m y 19 m y 20...
For the rest of the lab, you will make the assumption that your data is approximately...
For the rest of the lab, you will make the assumption that your data is approximately normally distributed. Use Excel to answer the following questions for the Net Sales data. Copy and paste the output below, don’t include as a separate file, make sure your x axis is labelled properly. You will have to “insert” your graphs in the appropriate places below. Please don’t upload more than one file for me to open and grade, your entire lab should be...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT