Loading...
Based on the requirements and use cases, identify the main objects of the system and analyze how they interact and relate to each other...
// Define your classes here
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
// Enum for Vehicle Types
enum VehicleType { MOTORCYCLE, CAR, TRUCK }
// Abstract Vehicle class
abstract class Vehicle {
private String licensePlate;
private VehicleType type;
public Vehicle(String licensePlate, VehicleType type) {
this.licensePlate = licensePlate;
this.type = type;
}
public String getLicensePlate() { return licensePlate; }
public VehicleType getType() { return type; }
}
// Car class extending Vehicle
class Car extends Vehicle {
public Car(String licensePlate) {
super(licensePlate, VehicleType.CAR);
}
}
// ParkingSpot class
class ParkingSpot {
private int id;
private boolean isAvailable;
private Vehicle assignedVehicle;
public ParkingSpot(int id) {
this.id = id;
this.isAvailable = true;
}
public boolean canFit(Vehicle vehicle) {
return isAvailable && vehicle.getType() == VehicleType.CAR; // Simplified for example
}
public void assign(Vehicle vehicle) {
this.assignedVehicle = vehicle;
this.isAvailable = false;
}
public void release() {
this.assignedVehicle = null;
this.isAvailable = true;
}
}
// ParkingTicket class
class ParkingTicket {
private String ticketId;
private Vehicle vehicle;
private ParkingSpot spot;
private LocalDateTime entryTime;
public ParkingTicket(String ticketId, Vehicle vehicle, ParkingSpot spot) {
this.ticketId = ticketId;
this.vehicle = vehicle;
this.spot = spot;
this.entryTime = LocalDateTime.now();
}
}
For each class, define the attributes (data) it will hold and the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation. Write your code in the code editor below.
Explain design tradeoffs you considered. Check and explain whether your design adheres to SOLID principles. Explain how your design can handle changes in scale and whether it would be easy to extend with new functionalities. Identify areas for future improvement...