ACTIVITY 1.5

In this activity you will modify the program that walks a list of 
cars, picking out the fastest and slowest cars, so that it uses
Java collections instead of the arrays.

1. 	As before, open Visual Studio Code by double-clicking its
	icon on the desktop, or by selecting it from the application
	menu.
	
2.	Your instructor will have given you the path to a folder
	containing the course exercises. It will be something like
	Documents\Course\1.5. From the main menu bar, select
	File | Open folder... then in the folder search dialog
	that appears, navigate to the folder your instructor
	gave you. Click 'Select folder' to open the folder.

3.	In the Explorer bar at the left of the screen, Click
	the 'src' folder, then click the 'App.java' file to
	open it.

4.	Make sure the App.java tab is selected at the top of the
	window, if you get a Java overview window hiding App.java.

5.  The code you see is the solution code to the previous
    exercise, 1.4. You will modify it to use ArrayLists to
    hold the cars and their top speeds.

6.  At the top of the source file, add import statements
    to import the List and ArrayList classes from the
    java.util library.

7.  Find the line that creates and initialises the cars
    array, and change it to create and empty ArrayList:

    ArrayList<String> cars = new ArrayList<String>();

8.  Now use cars.add("cartype"); six times to add each
    of the car names in turn.

9.  Do the same as steps 7 and 8 with the topSpeed 
    array, but use an ArrayList<Integer> instead. 
    Note that we use ArrayList<Integer> not 
    ArrayList<int>.

10. Your code in the for loop can no longer use the
    cars.length field to get the length of the array,
    because it is no longer an array. Instead, you must
    replace .length with .size() as ArrayLists measure
    their current length by using a size() method.

11. Wherever your code uses square brackets to access
    an element in the array, replace it with a call to
    .get(index) instead. For example:

    topSpeed[i] is replaced with topSpeed.get(i)

12. Save, compile and run your java file. You should
    still get the correct results of "Trabant" and
    "Bugatti".

IF YOU HAVE TIME ...

13. You will now modify the program again to use maps.
    Replace the cars declaration with a HashMap
    declaration:

    Map<String, Integer> cars = new HashMap<String, Integer>();

14. Replace each cars.add line with a cars.put line that
    inserts both the car name and the car top speed. For
    example:

    cars.put("Trabant", 45);

15. You can completely delete the topSpeed declaration and
    all the topSpeed.add(...) calls underneath it.

16. Add variables to track the fastest and slowest cars
    and their speeds:

    int topSpeed = 0, bottomSpeed = Integer.MAX_VALUE;
    String fastCar = "", slowCar = "";

17. Add a for loop that uses the iterator syntax to walk
    through each entry in the map in turn:

    for(String car : cars.keySet()) {
    }

18. Now add code to the body of the for loop that searches
    for the fastest car:

    int carSpeed = carMap.get(car);
    if(carSpeed > topSpeed || fastCar == "") {
        fastCar = car;
        topSpeed = carSpeed;
    }

19. Add a println line after the closing brace of the
    for loop that outputs the name of the fastest car:

    System.out.println("The fastest car is the " + fastCar);

20. Save your file, compile and run to see if the program
    still reports the Bugatti as the fastest car.

21. Now add an extra if statement to the for loop body
    that captures the slowest car, and check to make sure
    the program still returns the Trabant when it is run.
         
YOU HAVE FINISHED!