0

How can l solve this

vehicle parking problem write a java program to manage a parking area. the parking area is 100 m. each vehicle comes the system should allocate a suitable space for this car according to its length and the available spaces. when a car leaves the parking, your system should mark its space as free. if two contiguous spaces are free you should merge them. there are 4 types of vehicles: truck with default length 7m, bus with default length 10m, car with default length 5m, and motorcycle with default length 2m. your program should provide a menu to enable the user to manage the parking. the menu should include: adding a vehicle, leaving a vehicle, show parking status (to show free space and occupied spaces). when a vehicle comes the user should enter its type and id. using car id the user can release it from the parking area. the user should also enter number of hours spent in the parking when release. using calcmoney function in each different type of vehicle the program should calculates the money to be payed

25th Dec 2022, 2:26 PM
Ahmed abdo
1 Answer
+ 2
As this is Java, you will need to design some classes. The parking lot can be implemented as a class which stores the status of the parking spaces and the vehicles. The space of 100 meters might be represented by an array of 100 booleans, each of the values meaning if that particular segment is taken or free. If you want to park a bus, you need to find the first position in the array where 10 consecutive positions are free. You could assign a "parking ticket" that points to the starting position of the parked vehicle in this array. But you could invent other possible solutions too. The vehicle could be an abstract class, and each particular vehicle type inheriting from it (only the size would be different).
25th Dec 2022, 3:23 PM
Tibor Santa
Tibor Santa - avatar