3. Collections

  • Feel free to use your laptop

  • You are strongly encourage to work with others

    • When you get stuck, ask those sitting around you for help

    • Get used to working together in the labs

    • Peer teaching and peer learning has been empirically shown to be very effective

3.1. Creating Objects

The goal is to make a program that will keep track of a suite of courses. To do this, two classes will be written — one for keeping track of the information about a single course, and another for keeping track of multiple courses. In this lab, the CourseList class will be created as the Course class was written in the previous lab.

3.1.1. Course List Class

A CourseList will be a collection of Course objects. Refer to the data structures review topic for guidance on creating this class. It is recommended to go through the topic and refactor the relevant code to fit the requirements of this lab.

  1. Make a CourseList class that has two private fields (list & size) and a constant for a default capacity

    • list will be an array that holds references to Course objects

    • size will be the number of Course objects currently in list

      • Remember, the capacity of the array and size are not the same thing

    • DEFAULT_CAPACITY is a constant that will be used for creating the list array if no capacity is provided

  2. Write two constructors

    • One takes no parameter and makes list based on DEFAULT_CAPACITY

    • The other takes a parameter initialCapacity for the starting capacity of list

    • Try to use constructor chaining

  3. Write an add method that takes a Course object and adds it to the collection

    • This will require a mechanism to “expand the capacity” of the array to work properly

  4. Write a contains method that takes a Course as a parameter and returns true if it exists in the collection and false otherwise

  5. Write a indexOf method that returns the index of a specified Course object

    • If no such Course exists, this method should throw an exception

  6. Write a remove method that takes a Course to remove from the collection as a parameter

    • If no such Course exists, this method should throw an exception

    • Make use of the Course object’s equals method

  7. Write a get method that returns the Course object at the specified index in the CourseList

    • If the provided index is out of bounds, this method should throw an exception

  8. Write a size method to return the number of Course objects in the collection

  9. Write a toString for the class

  10. Test the CourseList class by creating an instance of it and using the methods

    • Be sure to check all methods

3.2. Kattis Problems

  1. https://open.kattis.com/problems/quadrant

  2. https://open.kattis.com/problems/judgingmoose

  3. https://open.kattis.com/problems/timeloop

  4. https://open.kattis.com/problems/oddities

  5. https://open.kattis.com/problems/fizzbuzz

  6. https://open.kattis.com/problems/twostones

  7. https://open.kattis.com/problems/spavanac

  8. https://open.kattis.com/problems/cetvrta

  9. https://open.kattis.com/problems/bus

  10. https://open.kattis.com/problems/timeloop

  11. https://open.kattis.com/problems/oddities

  12. https://open.kattis.com/problems/fizzbuzz

  13. https://open.kattis.com/problems/sibice

  14. https://open.kattis.com/problems/datum

  15. https://open.kattis.com/problems/dicecup

  16. https://open.kattis.com/problems/autori

  17. https://open.kattis.com/problems/apaxiaaans

  18. https://open.kattis.com/problems/hissingmicrophone

  19. https://open.kattis.com/problems/trik

  20. https://open.kattis.com/problems/pot

  21. https://open.kattis.com/problems/filip

  22. https://open.kattis.com/problems/reversebinary

  23. https://open.kattis.com/problems/sevenwonders

  24. https://open.kattis.com/problems/zamka

  25. https://open.kattis.com/problems/bijele

  26. https://open.kattis.com/problems/cold

  27. https://open.kattis.com/problems/nastyhacks

  28. https://open.kattis.com/problems/grassseed

  29. https://open.kattis.com/problems/pet

  30. https://open.kattis.com/problems/batterup

  31. https://open.kattis.com/problems/aboveaverage

  32. https://open.kattis.com/problems/icpcawards

  33. https://open.kattis.com/problems/quickbrownfox

  34. https://open.kattis.com/problems/nodup

  35. https://open.kattis.com/problems/conundrum

  36. https://open.kattis.com/problems/bela

  37. https://open.kattis.com/problems/kornislav