← Back to Week 2 Hub
Workbook 2a — Exercise 4

Vehicle Inventory

Menu-driven app to list, search, and add vehicles using arrays of objects  |  Workbook p.78-79

What You're Building

Build a dealership inventory system. Create a Vehicle class with five properties: vehicle ID, make/model, color, odometer reading, and price. Your program starts with an array that can hold up to 20 vehicles, preloaded with 6. The user sees a menu and can: list all vehicles, search by make/model, search by price range, search by color, add a new vehicle, or quit.

Vehicle Class Fields:

vehicleIdUnique identifier (int) makeModele.g. "Honda Civic" colore.g. "Red" odometerReadingMiles on the vehicle (int) priceAsking price (double)
Example Run
The Main Menu
What do you want to do?
1 - List all vehicles
2 - Search by make/model
3 - Search by price range
4 - Search by color
5 - Add a vehicle
6 - Quit

Enter your command: 1
Listing All Vehicles
ID: 10112 2018 Honda Civic Red 45000 mi $15,000.00
ID: 10113 2020 Toyota Camry Blue 32000 mi $18,500.00
ID: 10114 2019 Ford F-150 Black 58000 mi $22,000.00
ID: 10115 2021 Honda Accord White 12000 mi $24,500.00
ID: 10116 2017 Chevy Malibu Red 67000 mi $11,200.00
ID: 10117 2022 Toyota RAV4 Blue 8000 mi $28,000.00
Searching by Price Range
Enter minimum price: 15000
Enter maximum price: 25000

Vehicles between $15,000.00 and $25,000.00:
ID: 10112 2018 Honda Civic Red 45000 mi $15,000.00
ID: 10113 2020 Toyota Camry Blue 32000 mi $18,500.00
ID: 10114 2019 Ford F-150 Black 58000 mi $22,000.00
ID: 10115 2021 Honda Accord White 12000 mi $24,500.00
Key detail: The array can hold 20 vehicles but starts with only 6. When the user adds a vehicle, it fills the next empty slot. You need to track how many vehicles are currently in the array.
Concepts You'll Use
Flow Diagram
Create Vehicle class 5 private fields + getters/setters
Preload 6 vehicles Into array of size 20
Show menu 6 options + prompt
Handle user choice 1-6: each option does something different
List / Search / Add Loop through array, filter matches
Quit selected? No: loop back to menu
Exit program User chose option 6

Workbook 2a, p.78-79 — Exercise 4: Vehicle Inventory

← Test Statistics Neighborhood Library →