Final Project Write a C program to manage a parking lot Buil
Solution
public class ParkingLot
{
Vector<Parkingspace> vacantParkingSpaces = null;
Vector<ParkingSpace> fullParkingSpaces = null;
int parkingSpaceCount = 0;
boolean isFull;
boolean isEmpty;
ParkingSpace findNearestVacant(ParkingType type)
{
Iterator<ParkingSpace> itr = vacantParkingSpaces.iterator();
while(itr.hasNext())
{
ParkingSpace parkingSpace = itr.next();
if(parkingSpace.parkingType == type)
{
return parkingSpace;
}
}
return null;
}
void parkVehicle(ParkingType type, Vehicle vehicle)
{
if(!isFull())
{
ParkingSpace parkingSpace = findNearestVacant(type);
if(parkingSpace != null)
{
parkingSpace.vehicle = vehicle;
parkingSpace.isVacant = false;
vacantParkingSpaces.remove(parkingSpace);
fullParkingSpaces.add(parkingSpace);
if(fullParkingSpaces.size() == parkingSpaceCount)
isFull = true;
isEmpty = false;
}
}
}
void releaseVehicle(Vehicle vehicle)
{
if(!isEmpty())
{
Iterator<ParkingSpace> itr = fullParkingSpaces.iterator();
while(itr.hasNext())
{
ParkingSpace parkingSpace = itr.next();
if(parkingSpace.vehicle.equals(vehicle))
{
fullParkingSpaces.remove(parkingSpace);
vacantParkingSpaces.add(parkingSpace);
parkingSpace.isVacant = true;
parkingSpace.vehicle = null;
if(vacantParkingSpaces.size() == parkingSpaceCount)
isEmpty = true;
isFull = false;
}
}
}
}
boolean isFull()
{
return isFull;
}
boolean isEmpty()
{
return isEmpty;
}
}
public class ParkingSpace
{
boolean isVacant;
Vehicle vehicle;
ParkingType parkingType;
int distance;
}
public class Vehicle
{
int num;
}
public enum ParkingType
{
motorcycle_spot,
compact_spot,
large_spot,
}
class ParkingLot
{
Space[][] spaces;
ParkingLot(wide, long); // constructor
FindOpenSpace(TypeOfvehicle); // find first open space where type matches
}
enum TypeOfSpace = {motorcycle_spot,compact_spot,large_spot };
enum TypeOfvehicle = {motorcycle,cars,buses };
class Space
{
TypeOfSpace type;
bool empty;
// gets and sets here
// make sure vehicle type
}
class vehicle
{
TypeOfvehicle type;
}
void main()
{
cout<<\"enter choice\ \";
cout<<\"1.setup the parking lot\ \";
cout<<\"2.edit\ \";
cout<<\"3.look for capacity\\\";
cout<<\"4.view level information\ \"
cout<<\"5.exit\";
cin>>&n
using switch case we call appropraite operations whatever we required..
thank you


