I am working on a school project that involves a parking lot. Our 'parking lot' contains a 10x10 grid and each space can either contain a vehicle, or be empty.
I have a superclass of vehicles and multiple subclasses of the vehicle class, such as motorbikes and vans that inherit attributes and methods from the superclass.
I have a method which returns a linked list of all the neighbours of each parking space. However the linked list stores the objects as the superclass type vehicle, no matter what subclass the object actually is.
I want to add methods that are dependent on what subclass of vehicles is a neighbour of a given spot ie whether it contains a motorbike or not.
How would I go about implementing this in my project? Thanks in advance.
I was expecting to be able to get the subclass type of each vehicle in the linked list but could not.
add methods that are dependent on what subclass of vehicles is a neighbour?v.getClass()and check on the name OR create a property (maybe aenum) to perform this operationinstanceof(e.g.if (obj instanceof MotorBike) { ... }) but the more Object Oriented solution is using methods like having each Vehicle having agetType()orisMotorBike()method