1.3-Object-Georienteerd-Programmeren

Car dealership

A car dealership trades (as you would have guessed) in cars. Keeping track of inventory (what cars are available) is something that is easily automated. Today we’ll write a very simple version of such a system.

Create a class Dealership with two public methods:

Note that the addCar method requires a Car instance as argument, so also create this Car class, with just two attributes: license plate and brand. Please make these attributes unchangable by only providing getters and a constructor to initially set them.

After you made sure your basic program works (please use our code or add some dummy data yourself), we would like you to add one additional check to the system: A dealership cannot have two cars with the same license plate. If you try to add a car with the same license plate (regardless of brand) to a Dealership instance that already has a car with the provided license plate, an IllegalArgumentException should be thrown. Update your code to show this and test if it works.

Sequence Diagram

A sequence diagram shows the flows of an action through the program. It shows which class calls which other class and how long that class is active during that time.

They can have varying levels of detail depending how close to the implementation they are.

Add Car

An instance does not exist until it is created, only then can it be used in following statements.

Number of cars by brand

Below is a sequence diagram that gives a suggestion of how the getNrOfCarsByBrand could work with how the classes interact with each other. This diagram does not show how to count the number of cars. That will be up to you.