Vehicle management system with inheritance and polymorphism

Java Hard classes

Task «Vehicle management system with inheritance and polymorphism»

Develop a class system for managing a fleet of vehicles. Create an abstract class `Vehicle` with fields: `id` (int), `brand` (String), `model` (String), `year` (int) and an abstract method `getInfo()`. Inherit from it the classes `Car` (additional field: `int doors`) and `Motorcycle` (additional field: `boolean hasSidecar`). Implement a `Fleet` class that contains a list of `Vehicle` and methods: `addVehicle(Vehicle v)`, `removeVehicle(int id)`, `getVehicleInfo(int id)` (returns information about the vehicle in the format: "id brand model year doors" for Car and "id brand model year sidecar" for Motorcycle, where sidecar is output as "yes" or "no"), `listAllVehicles()` (outputs information about all vehicles, each on a new line). In `main`, read from stdin the number of commands N, then N commands: "ADD id brand model year type [param]", "REMOVE id", "INFO id", "LIST". For ADD, type can be "Car" (then param = doors) or "Motorcycle" (param = "yes"/"no"). It is guaranteed that ids are unique. Output the results of the INFO and LIST commands.

Input Format

On the first line, an integer N (1 <= N <= 100). Then N lines of commands: ADD id brand model year type param, REMOVE id, INFO id, LIST.

Output Format

For each INFO command, output a line with information about the vehicle. For the LIST command, output information about all vehicles in the order they were added, one line per vehicle. If a vehicle with the specified id is not found for INFO or REMOVE, output "Not found".

Examples

Example 1

INPUT
6 ADD 1 Toyota Camry 2015 Car 4 ADD 2 Harley Davidson 2020 Motorcycle yes INFO 1 LIST REMOVE 1 LIST
OUTPUT
1 Toyota Camry 2015 4 1 Toyota Camry 2015 4 2 Harley Davidson 2020 yes 2 Harley Davidson 2020 yes

Example 2

INPUT
4 ADD 10 BMW X5 2022 Car 5 INFO 10 INFO 20 LIST
OUTPUT
10 BMW X5 2022 5 Not found 10 BMW X5 2022 5

Example 3

INPUT
5 1 2 3 4 5
OUTPUT
main.java