Skip to content

Instantly share code, notes, and snippets.

@Ellpeck

Ellpeck/Hints.md Secret

Last active October 17, 2019 18:02
Show Gist options
  • Save Ellpeck/3bdc69845d0d4c0e9511511dd06cfdc1 to your computer and use it in GitHub Desktop.
Save Ellpeck/3bdc69845d0d4c0e9511511dd06cfdc1 to your computer and use it in GitHub Desktop.

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 a for loop and find the first available spot using a null comparison
  • To add info about a new customer, create a static addCustomer method that adds them to the list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment