Data Structures
Overview
Teaching: 60 min
Exercises: 60 minQuestions
How do we use arrays, ArrayLists and HashaMaps to represent collections in Java?
Objectives
Build on the example Rectangle class with arrays, ArrayLists and HashMaps.
Array handling
Write a method called emailAddresses that takes two array arguments called first and last and an String argument called domain. The method should be declared in a class in a class called EmailFormatter.java.
Implement the method to use inputs from the corresponding arguments first and last to return a list of suggested email addresses that follow the convention of containing the first name, followed by a full stop and then the last name and finally the domain.
ArrayList handling
Write a method called fiveASideSelector that takes an ArrayList
ArrayList inserts
Imagine you are designing a program to help organise a queue of people arriving and leaving a dental clinic waiting room. People should be called up to see dentist in the order that they arrive. Write a method called arrival that takes an argument containing the new arrival’s name and adds their name to the queue (a list of names). Also write a function called next patient that takes an integer argument called position. This function should return the name of the person in the given position in the queue or return the name of the person that is next in the queue if no argument is provided for position. You should make sure that names of people that have been returned by the next patient function are removed from the queue. The method should be declared in a class called DentistWaitingRoom.java.
Create array of objects for the project
- Initialise a static ArrayList of shapes in a class called GameLogic. Declare four Wall objects that form the shape of a square when ‘painted’ and add them to the list.
- Create two a Paddle objects that are placed on each side and create a Ball object that is placed in the middle. Add these Shape subclasses to the list in GameLogic.
- Update the paint method to iterate over all objects in GameLogic.
Key Points
Object-oriented programming is a programming paradigm that uses abstraction (in the form of classes and objects) to create models based on the real world environment