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;
-
Write a function that will let you enter numbers into an ArrayList. Enter numbers until you enter a -1.
public void enter()
-
Write a function that will print out the names in the ArrayList
public void print()
-
Write a function that will print out the names in the ArrayList in reverse order
public void printReverse()
-
Write a function that will print out the names in the ArrayList. Use a for-each loop.
public void print()
-
Write a function that will delete the item at the front of the list and put it onto the back.
public void putFrontOnBack()
-
Return the name that is alphabetically first in the list.
public String getSmallest()
-
public int getSum()
-
public void printEveryOther()
-
public Double getBiggest()
-
public void removeAllOddNumbers()
-
public void switchNumbers()
4 5 9 4 5 6 becomes 5 4 4 9 6 5
-
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()
- 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)
- 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()
- 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
-
Write a function that will return the location of the biggest number in an ArrayList.
public int getLocation()
-
Delete all elements that were originally in odd spots.
- 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()
-
public double getEvenAverage()
-
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
|