Overview
For this assignment, we will practice using stacks and queues. In this exercise, you will create two stacks and a queue to keep track of cars using a parking lot. We will use the nature of the stacks and queues to solve the problem.
Specifications
Rules
FIU has opened a new valet parking lot next to the PC building that requires a special decal to park. If the car does not have the correct parking decal, the driver should be told nicely that they do not have the correct permit to park in this lot.
The parking lot is a “last-in, first-out” stack. When parking a car, the program must first check to see if the car has the correct decal. If it does have the correct permit, the car may be added to the lot as long as there is enough room. To park a car, the car’s license tag is added to the parking lot stack. The parking lot can hold 20 cars at a time. If the parking lot is full, a waiting car can be added to a waiting queue. When a car leaves the lot, the next car in the queue will be able to park in the parking lot. When a car owner retrieves a vehicle that wasn’t the last one in, the cars blocking it must temporarily move to the street so that the requested vehicle can leave.
Write a program that models this behavior, using one stack for the driveway and one stack for the street. A queue will be used to store the cars waiting for a place to park of the lot is full
Use integers as license plate numbers. Positive numbers add a car, negative numbers remove a car, zero stops the simulation. If the stack representing the parking lot is full, the car waiting should be added to the queue. Print out the parking lot stack and the waiting queue after each operation is complete.
Expected Output:
The expected output should contain the list of cars currently parked in the parking lot and the list of cars currently waiting to park.
Java Requirements
The program must
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Stack<Integer> parkingLot = new Stack<>();
Stack<Integer> street = new Stack<>();
Queue<Integer> waitingCars = new LinkedList<>();
while (true) {
System.out.println("\nEnter the positive license number to park the car");
System.out.println("Enter the negative license number to remove the car");
System.out.println("Enter zero to stop simulation");
int licensePlatenumber;
try{
licensePlatenumber = Integer.parseInt(sc.nextLine());
} catch (Exception e){
System.out.println("You do not have the permit to park here\n");
continue;
}
if(licensePlatenumber == 0){
break; // User entered zero so stop the simulation.
}
else if(licensePlatenumber > 0){ // positive number means user wants to park the car in the lot.
if(parkingLot.size() < 20){
parkingLot.push(licensePlatenumber);
}
else{
waitingCars.add(licensePlatenumber);
}
System.out.println("Parking lot after this operation has following cars" + parkingLot);
System.out.println("following cars are waiting in queue" + waitingCars);
}
else{ // negative number means user wants to remove the car from the lot.
licensePlatenumber = -1 * licensePlatenumber;
if(parkingLot.search(licensePlatenumber) == -1){
System.out.println("This car is not present in the parking lot\n"); // When user enters a number which is not present in the parking lot.
}
else{
while(parkingLot.peek()!= licensePlatenumber){
street.push(parkingLot.peek());
parkingLot.pop();
}
parkingLot.pop();
while(!street.empty()){
parkingLot.push(street.peek());
street.pop();
}
if(waitingCars.size() > 0){
parkingLot.push(waitingCars.remove());
}
}
System.out.println("Parking lot after this operation has following cars" + parkingLot);
System.out.println("following cars are waiting in queue" + waitingCars);
}
}
}
}

Overview For this assignment, we will practice using stacks and queues. In this exercise, you will...
Overview For this assignment, we will practice using stacks and queues. In this exercise, you will create two stacks and a queue to keep track of cars using a parking lot. We will use the nature of the stacks and queues to solve the problem. Specifications Rules FIU has opened a new valet parking lot next to the PC building that requires a special decal to park. If the car does not have the correct parking decal, the driver should...
Queues and Stacks Purpose: To review queues and stacks in Java, and to use the built-in Stack class and Queue interface. The Stack class is a generic class containing these methods: public void push(E value) - pushes a new value onto the Stack public E pop() - pops the next value off of the stack and returns it; throws EmptyStackExceptionl if stack is empty public E peek() - returns the next value on the Stack but does not pop it...
Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example in the PPT) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked beyond their time...
Module 4 follow the materials available at Topic - Stacks and Queues. You should have a good understanding of Lists at Topic - Basic Data structures as a Queue and a Stack are simply implementation of a List with specific properties. Assignment - Implement a Stack computer in Javascript (you will turn in a link to your program in JSFiddle). This is a simple computer that keeps a stack, when a number is entered it goes onto the top of the...
Questions Submission Question 2: Stacks Problem Write a program that keeps track of where cars are located in a parking garage to estimate the time to retrieve a car when the garage is full. This program will demonstrate the following: How to create a list for use as a stack, How to enter and change data in a stack. Solving the Problem Step 1 In Python, the stack data structure is actually implemented using the list data structure with a...
The CSC326 parking garage contains 2 lanes, each capable of holding up to 10 cars. There is only a single entrace/exit to the garage at one end of the lanes. If a customer arrives to pick up a car which is not nearest the exit, all cars blocking the car's path are moved into the other lane. If more cars still must be moved out of the way, they go into the street. When the customer's car is driven out,...
The purpose of this problem is to gain familiarity with stacks and queues. You have three jugs that can hold c1, c2, and c3 liters of water, respectively. Initially, jug 1 is full and the other two jugs are empty. You can repeat the following procedure any number of times: Choose two of the jugs and pour the contents of one into the other until either the first is empty or the second is full. Your goal is to end...
using java:
For this exercise, you will design a set of classes that work
together to simulate a parking officer checking a parked car
issuing a parking ticket if there is a parking violation. Here are
the classes that need to collaborate:
• The ParkedCar class: This class should
simulate a parked car. The car has a make, model, color, license
number. •The ParkingMeter class: This class should
simulate a parking meter. The class has three parameters:
− A 5-digit...
This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...
Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your own Array-Based Stack (ABS) and Array-Based Queue (ABQ). A stack is a linear data structure which follows the Last-In, First-Out (LIFO) property. LIFO means that the data most recently added is the first data to be removed. (Imagine a stack of books, or a stack of papers on a desk—the first one to be removed is the last one placed on top.) A queue...