Post date: Jul 21, 2019 5:21:27 AM
Chapter 14: Generics and the ArrayList Class
14.1 The ArrayList Class
Lab Exercise:
Ex 1:
Write a Java program that get 10 real numbers from the user using an ArrayList. Calculate and display the total and the average of these numbers, then ask the user to enter a number and display whether the number can be found in the ArrayList or not.
Ex 2:
Write a Java class named ArrayListSort that has 2 static methods selectionSort and bubbleSort that takes an ArrayList<String> as argument.
Chapter 14: Generics and the ArrayList Class
14.2 Generics
Lab Ex 1 (InformIT.com):
Write a generic method to exchange the positions of two different elements in an array.
Lab Ex 2 (adapted from Programming Project 4 p. 831):
Write a generic class, MyMathClass, with a type parameter T where T is a numeric object type (e.g., Integer, Double, or any class that extends java.lang.Number). Add a method named average that takes an ArrayList of type T and returns as a double the average of the values in the ArrayList. Use the doubleValue() method in the Number class to retrieve the value of each number as a double.