educative.io

Educative

ParkingSpot.assignVehicle?

Hello,

Just a design question, why does the parking spot assigns a vehicle? and who calls it? Is it the ParkingLot or ParkingFloor.

I would suggest moving vehicle parking to ParkingLot and using ParkingLot as mediator => Vehicle does not reference spot and spot does not reference vehicle. Relations are kept in ParkingLot.
(Same would go for tickets).

Also point 12, was never tackled in the solution (payment per hour + increments).

Thanks

Hi @Joseph,

ParkingLot should be calling ‘assignVehicle()’. This information will be used to find out if a spot is free or not. It can also be used to find out where a particular vehicle is parked.

When you say ‘vehicle parking’ did you mean ‘assignVehicle’ to a spot? Did you mean to move the ‘assignVehicle’ to ‘parkingLot’.

The payment can be calculated as follows:

 public double calculatePayment(Date startTime){
        Date endTime = new Date();
        long diff = endTime.getTime() - startTime.getTime();
        int diffHours = (int) Math.ceil((double)diff / 60);
        double payment = 0.0;
        for (int hour = 1; hour <= diffHours; hour++) {
          // assuming 'parkingRate' is a map containing parking rate for each hour
          payment += parkingRate.get(hour);
        }
        return payment;
     }

Where did you implement parkingspot.getNumber() method? You totally forgot to put it there.
freeHandicappedSpotCount++ or some freeSpotCount is incremented whenever freespot is called. However freeSpotCount is not decremented when the new car parking takes place. Come on. What is the initial freeHandicappedSpotCount?

1 Like

Really confusing codes and not focus on the main requirement such as calculatePayment and totalFreeSpots. Really?

2 Likes

@Design_Gurus The key piece of design such as the flow of Vehicle assignment is missing.

5 Likes

I find that parkinglot assigning vehicle to a spot is count-intuitive. I have never seen or heard a parking lot where a parking spot is being assigned to the vehicle at entrance. It is typically the driver park the car at whichever spot, then the parking floor sensor figures it out.

1 Like