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:
void addCar(Car newCar)
which allows you to register a new car with the dealership.int getNrOfCarsByBrand(String brand)
which you can use to query the number of cars of any given brand.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.
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.
An instance does not exist until it is created, only then can it be used in following statements.
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.