Topic 9 - Array List Questions (8 days)




The following methods have an ArrayList as a private instance variable. It will be one of the following.

Use :
private ArrayList<String> ar;
or
private ArrayList<Integer> ar;

  1. Write a function that will let you enter numbers into an ArrayList. Enter numbers until you enter a -1.

    public void enter()

  2. Write a function that will print out the names in the ArrayList

    public void print()

  3. Write a function that will print out the names in the ArrayList in reverse order
    public void printReverse()

  4. Write a function that will print out the names in the ArrayList. Use a for-each loop.
    public void print()

  5. Write a function that will delete the item at the front of the list and put it onto the back.
    public void putFrontOnBack()

  6. Return the name that is alphabetically first in the list.

    public String getSmallest()

  7. public int getSum()

  8. public void printEveryOther()

  9. public Double getBiggest()

  10. public void removeAllOddNumbers()

  11. public void switchNumbers()

    4 5 9 4 5 6 becomes 5 4 4 9 6 5

  12. Write a function that will get the sum of all the numbers in the arraylist. When your current sum gets to be 100 or more delete the number that put you over 100. Then start getting the sum again.

    For example if list was :
    40 30 10 50 20 40 30 70 80 30 40 50 30
    The ArrayList would become :
    40 30 10 20 40 30 80 40 50
    public void deleteSome()

  13. Write a method that will delete the first occurence of a value sent as a parameter from an ArrayList of Integers. The Arraylist is holding Integers. Return true or false from function.

    public boolean delete( int n)

  14. Write a method that will shift everyone 2 spots in the ArrayList. If ArrayList was 3 4 6 8 9 it would become 8 9 3 4 6 public void shift2()

  15. Write a method that will change any odd numbers to the next even number. arrayList is holding Integers.

    void changeOdd() 2 7 4 6 9 would become 2 8 4 6 10

  16. Write a function that will return the location of the biggest number in an ArrayList.

    public int getLocation()

  17. Delete all elements that were originally in odd spots.

  18. Write a function that will delete the biggest number in an ArrayList of Integer objects. You must call the function written in number 16 to get credit.

    public void deleteBiggest()

  19. public double getEvenAverage()

  20. public void rotate(int times)

    Take "times" numbers from front and put them onto the back of the list. For example if List held :
    3 4 5 13 9 12 45 17 99 32 and times is 3 the array would become :
    13 9 12 45 17 99 32 3 4 5
HOME