Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The 24/7 parking garage is operated without any computerized system. In order to

ID: 3888890 • Letter: T

Question

The 24/7 parking garage is operated without any computerized system. In order to maximize the profit, the owner of the garage hires you to develop a computer system to help manage the parking garage so that drivers can find and reserve available parking places.

1. There are in total 20 parking spaces

2. Each parking space has three states: “available,” “reserved,” or “occupied”

3. A driver may reserve a parking space by specifying a time slot

4. The driver may modify their existing reservation(s) before the starting time of a particular reservation.

5. A driver may extend their current occupancy of a parking space as long as it is before the end of the reservation.

Assume that you only implement a one-day (24-hour) parking lot reservation. The time each customer reserve a parking spot is in multiples of 1 hour (e.g. 1 hour, 2 hours, 3 hours. Not 1.5 hours, 2.75 hours).

Your program will ask the customer the current time, and show the current states of all 20 parking spots. The customer may reserve an “available” parking spot and specify the time slot.

Java Implementation please, thank you!

Explanation / Answer

See below the list of classes

Garage

import java.util.ArrayList;

import java.util.List;

public class Garage

{

List<ParkingSlot> parkingslots=new ArrayList<ParkingSlot>();

public Garage()

{

for(int i=1;i<=20;i++)

{

parkingslots.add(new ParkingSlot());

}

}

public List<ParkingSlot> getParkingSlotsForCurrentTime()

{

return parkingslots;

}

}

ParkingSlots:

import java.util.ArrayList;

import java.util.List;

/*

* this Class represents the each praking slot in garage.

* this parking slot will maintain list of all time slots throghout a day. that will be a 24 time slots

*/

public class ParkingSlot

{

public static final String AVAILABLE = "AVAILABLE";

public static final String RESERVED = "RESERVED";

public static final String OCCUPIED = "OCCUPIED";

List<TimeSlot> timeSlot=new ArrayList<>();

public ParkingSlot()

{

for(int i=0;i<24;i++)

{

TimeSlot slot=new TimeSlot();

slot.setSlot(i);

slot.setStatus(AVAILABLE);

timeSlot.add(slot);

}

}

public List<TimeSlot> getTimeSlot() {

return timeSlot;

}

public void setTimeSlot(List<TimeSlot> timeSlot) {

this.timeSlot = timeSlot;

}

}

TimeSlots:

public class TimeSlot

{

private int slot;

private String status;

public int getSlot() {

return slot;

}

public void setSlot(int slot) {

this.slot = slot;

}

public String getStatus() {

return status;

}

public void setStatus(String status) {

this.status = status;

}

}

Driver class which contains all implementiion logic:

import java.util.Scanner;

public class Driver {

public static void main(String[] args)

{

Garage garage =new Garage();

String ans=null;

do

{

Scanner sc= new Scanner(System.in);

dispayAllParkingSlots(garage);

reserveSlot(garage);

System.out.println("Do you want to quite? y/n");

ans=sc.nextLine();

}

while(!"y".equals(ans));

}

private static Garage dispayAllParkingSlots(Garage garage)

{

Scanner sc=new Scanner(System.in);

System.out.println("eneter your time slot");

int timtslot=sc.nextInt();

int i=1;

System.out.println("see below the list of Parking slots and status for Time slot "+i+ " to "+(i+1));

for(ParkingSlot slot : garage.getParkingSlotsForCurrentTime())

{

System.out.println("parking slot No : "+i+" is in Status "+slot.getTimeSlot().get(timtslot-1).getStatus());

i++;

}

return garage;

}

private static void reserveSlot(Garage garage)

{

int timtslot;

Scanner sc=new Scanner(System.in);

System.out.println("Enter the Parking slot number to reserve");

int parkingslotNo=sc.nextInt()-1;

System.out.println("Enter the Time slot to reserve");

timtslot=sc.nextInt()-1;

ParkingSlot slot=garage.getParkingSlotsForCurrentTime().get(parkingslotNo);

if(!slot.getTimeSlot().get(timtslot).getStatus().equals(ParkingSlot.AVAILABLE))

{

System.out.println("this Parking slot is not available for requested time slot");

System.out.println("Please choose different parking slot");

}

else

{

slot.getTimeSlot().get(timtslot).setStatus(ParkingSlot.RESERVED);

System.out.println("Requested Time slot is reserved");

}

}

}