import [Link].
Scanner;
public class ParkingSystem {
// Array representing parking spots (1 = occupied, 0 = available)
private static int[] parkingLot;
private static final int TOTAL_SPOTS = 100;
public static void main(String[] args) {
parkingLot = new int[TOTAL_SPOTS];
Scanner scanner = new Scanner([Link]);
while (true) {
[Link]("Parking System Menu:");
[Link]("1. Park a container");
[Link]("2. Remove a container");
[Link]("3. Display available spots");
[Link]("4. Exit");
[Link]("Choose an option: ");
int choice = [Link]();
switch (choice) {
case 1:
parkContainer(scanner);
break;
case 2:
removeContainer(scanner);
break;
case 3:
displayAvailableSpots();
break;
case 4:
[Link]("Exiting parking system...");
[Link](0);
break;
default:
[Link]("Invalid option. Please try again.");
// Park a car in the first available spot
private static void parkContainer(Scanner scanner) {
for (int i = 0; i < TOTAL_SPOTS; i++) {
if (parkingLot[i] == 0) {
parkingLot[i] = 1; // Mark the spot as occupied
[Link]("Container parked in spot " + (i + 1));
return;
}
}
[Link]("No available spots! The parking lot is full.");
// Remove a car from a specified spot
private static void removeContainer(Scanner scanner) {
[Link]("Enter the parking spot number to remove the car from: ");
int spot = [Link]();
if (spot < 1 || spot > TOTAL_SPOTS) {
[Link]("Invalid spot number.");
return;
if (parkingLot[spot - 1] == 0) {
[Link]("No Container is parked in this spot.");
} else {
parkingLot[spot - 1] = 0; // Mark the spot as available
[Link]("Container removed from spot " + spot);
// Display all available parking spots
private static void displayAvailableSpots() {
[Link]("Available spots: ");
for (int i = 0; i < TOTAL_SPOTS; i++) {
if (parkingLot[i] == 0) {
[Link]((i + 1) + " ");
[Link]();