Let's imagine you're managing a small car dealership. You want to have a way of managing all of the cars you have in stock. This includes keeping track of their brand names, their horsepower, their license plate texts and their mileage. Currently, you have 15 parking spots for cars you can sell, 4 of which are already occupied with cars. Additionally, you keep track of a list of all the customers you have had so far (namely, you store their first and last names as well as the city they live in). At the current time, you've already had 3 customers. Additionally, you want to have a way of adding a new car to the first available parking spot, as well as a way to store the data of a new customer easily.
- The cars are represented by a
Car
class like before - The customers are represented by a
Customer
class which contains several fields for the different types of information - The parking spots are represented by a static field
Car[]
- The list of customers is represented by a static field
ArrayList<Customer>
- To add a new car, create a static
addCar
method where you iterate through the array of cars using afor
loop and find the first available spot using anull
comparison - To add info about a new customer, create a static
addCustomer
method that adds them to the list