Solution Review: Car Parking Robot
The solution to the 'Car Parking Robot' challenge.
Rubric criteria
Solution
Press + to interact
class CarParking{public static void main(String args[]){robot(10, 10, 19);}public static void robot(int width, int length, int cars){int counter = 0; // Number of parked carsfor (int i = 0; i < length; i++){for (int j = 0; j < width; j++) // Filling row-wise{if (j % 4 == 0) // Leaving three columns{if (counter < cars) // If any car left{System.out.print("đźš—"); // Parking the carcounter++;}else // No car left{System.out.print("đźš«"); // Marking space as available}}else // distance less than 3 meters{System.out.print(" "); // Adding the space}}System.out.print("\n"); // Row completed, move to next row}}}
Rubric-wise explanation
Point 1:
Look at the header of the robot()
function at ...
Get hands-on with 1400+ tech skills courses.