Question

NAME CSC 236- ArrayList and Generics coding quz Write Java statements to odd the integers 1001, 1100, and 1110 to the resulting ArrayList from question 4 above. 5) 6) Write the Java statement to display the size of The resulting ArrayList from question 5 above. Write Java statements that use a for each loop to cycle through all the elements in on ArrayList of doubles named grades. 7) Write a Java method named average. The method should take an ArrayList of Integers as a parameter, compute the aw and return the average to the calling method 8)


please help with this homework, thanks !!

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

5)adding integrs to arrraylist.

ArrayList<Integer> list = new ArrayList<>();
        list.add(1001);
        list.add(1100);
        list.add(1110);

//create the list with the ArrayList and add the elements.

6)To display the size of ArrayList

int count = list.size();
        System.out.println("Count: " + count);

//list.size() ->used to find the arraylist size.

7)using for loop to cycle through the elements

ArrayList<Double> list = new ArrayList<>();
for (Double grades : list) {
            System.out.println(grades);
  }

8)find average:

float avg= average(list) // call method average with parameter Integer ArrayList list

System.out.println("Average: "+avg);

//average function. compute the average and return the value.

public float average(ArrayList<Integer> list) {
 int  total=0;
 float avg=0;
    for (int elem : list) {

total+=elem;

}

avg=(float)total / list.size();

return avg;

}

//any clarification please do comments

Add a comment
Know the answer?
Add Answer to:
please help with this homework, thanks !! NAME CSC 236- ArrayList and Generics coding quz Write...
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
  • Please help. I need a very simple code. For a CS 1 class. Write a program...

    Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...

  • The following are screen grabs of the provided files Thanks so much for your help, and have a n...

    The following are screen grabs of the provided files Thanks so much for your help, and have a nice day! My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...

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