├── .gitignore ├── justpark_class_diagram.png ├── other_resources.txt ├── readme.md └── src └── com └── justpark ├── Main.java ├── exceptions ├── MalformedVehicleException.java ├── SpotAlreadyFreeException.java ├── SpotAlreadyOccupiedException.java └── SpotNotAddedException.java └── models ├── Address.java ├── DBObject.java ├── Person.java ├── accounts ├── Account.java ├── AccountStatus.java ├── Admin.java ├── Attendant.java └── Customer.java ├── electronics ├── AutoExitPanel.java ├── ChargingPanel.java ├── CustomerInfoPortal.java ├── DisplayBoard.java ├── Electronics.java └── EntrancePanel.java ├── parking ├── Floor.java ├── Gate.java ├── GateType.java ├── GroundFloor.java ├── ParkingLot.java ├── Ticket.java ├── TicketStatus.java ├── interfaces │ ├── HasDisplay.java │ ├── IssuesTicket.java │ └── PaymentEnabled.java └── spots │ ├── CompactSpot.java │ ├── ElectricSpot.java │ ├── HandicappedSpot.java │ ├── LargeSpot.java │ ├── MotorcycleSpot.java │ ├── Spot.java │ ├── SpotStatus.java │ └── SpotType.java └── vehicles ├── Car.java ├── Electric.java ├── Motorcycle.java ├── Truck.java ├── Van.java ├── Vehicle.java └── VehicleType.java /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | out/ 3 | *.iml 4 | -------------------------------------------------------------------------------- /justpark_class_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AgarwalPragy/MachineCodingParkingLot/397a15e5925df4253b65655e85c2ac678e66f609/justpark_class_diagram.png -------------------------------------------------------------------------------- /other_resources.txt: -------------------------------------------------------------------------------- 1 | https://medium.com/@andrewhowdencom/anatomy-of-a-good-commit-message-acd9c4490437 2 | https://www.slideshare.net/TarinGamberini/commit-messages-goodpractices 3 | 4 | https://github.com/AgarwalPragy/MachineCodingParkingLot 5 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Requirements 2 | 3 | 1. The parking lot should have multiple floors where customers can park their cars. 4 | 1. The parking lot should have multiple entry and exit points. 5 | 1. Customers can collect a parking ticket from the entry points and can pay the parking fee at the exit points on their way out. 6 | 1. Customers can pay the tickets at the automated exit panel or to the parking attendant. 7 | 1. Customers can pay via both cash and credit cards. 8 | 1. Customers should also be able to pay the parking fee at the customer’s info portal on each floor. If the customer has paid at the info portal, they don’t have to pay at the exit. 9 | 1. The system should not allow more vehicles than the maximum capacity of the parking lot. If the parking is full, the system should be able to show a message at the entrance panel and on the parking display board on the ground floor. 10 | 1. Each parking floor will have many parking spots. The system should support multiple types of parking spots such as Compact, Large, Handicapped, Motorcycle, etc. 11 | 1. The Parking lot should have some parking spots specified for electric cars. These spots should have an electric panel through which customers can pay and charge their vehicles. 12 | 1. The system should support parking for different types of vehicles like car, truck, van, motorcycle, etc. 13 | 1. Each parking floor should have a display board showing any free parking spot for each spot type. 14 | 1. The system should support a per-hour parking fee model. For example, customers have to pay $4 for the first hour, $3.5 for the second and third hours, and $2.5 for all the remaining hours. 15 | 16 | # Actors 17 | 18 | 1. Admin: Mainly responsible for adding and modifying parking floors, parking spots, entrance, and exit panels, adding/removing parking attendants, etc. 19 | 1. Customer: All customers can get a parking ticket and pay for it. 20 | 1. Parking attendant: Parking attendants can do all the activities on the customer’s behalf, and can take cash for ticket payment. 21 | 1. System: To display messages on different info panels, as well as assigning and removing a vehicle from a parking spot. 22 | 23 | # Usecases 24 | 25 | 1. Add/Remove/Edit parking floor: To add, remove or modify a parking floor from the system. Each floor can have its own display board to show free parking spots. 26 | 1. Add/Remove/Edit parking spot: To add, remove or modify a parking spot on a parking floor. 27 | 1. Add/Remove a parking attendant: To add or remove a parking attendant from the system. 28 | 1. Take ticket: To provide customers with a new parking ticket when entering the parking lot. 29 | 1. Scan ticket: To scan a ticket to find out the total charge. 30 | 1. Credit card payment: To pay the ticket fee with credit card. 31 | 1. Cash payment: To pay the parking ticket through cash. 32 | 1. Add/Modify parking rate: To allow admin to add or modify the hourly parking rate. -------------------------------------------------------------------------------- /src/com/justpark/Main.java: -------------------------------------------------------------------------------- 1 | package com.justpark; 2 | 3 | import com.justpark.models.Address; 4 | import com.justpark.models.Person; 5 | 6 | public class Main { 7 | public static void main(String[] args) { 8 | System.out.println("Hello everyone!"); 9 | Address a = new Address.Builder() 10 | .state("Maharashtra") 11 | .country("India") 12 | .zipCode("00000") 13 | .city("Pune") 14 | .streetAddress("Amanora Chambers, IB Office") 15 | .build(); 16 | 17 | Person atul = new Person.Builder("Atul") 18 | .phoneNumber("sfsdf") 19 | .build(); 20 | 21 | System.out.println(a.toString()); 22 | System.out.println(atul.toString()); 23 | } 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/com/justpark/exceptions/MalformedVehicleException.java: -------------------------------------------------------------------------------- 1 | package com.justpark.exceptions; 2 | 3 | public class MalformedVehicleException extends Throwable { 4 | public MalformedVehicleException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/exceptions/SpotAlreadyFreeException.java: -------------------------------------------------------------------------------- 1 | package com.justpark.exceptions; 2 | 3 | public class SpotAlreadyFreeException extends Throwable { 4 | public SpotAlreadyFreeException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/exceptions/SpotAlreadyOccupiedException.java: -------------------------------------------------------------------------------- 1 | package com.justpark.exceptions; 2 | 3 | public class SpotAlreadyOccupiedException extends Throwable { 4 | public SpotAlreadyOccupiedException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/exceptions/SpotNotAddedException.java: -------------------------------------------------------------------------------- 1 | package com.justpark.exceptions; 2 | 3 | public class SpotNotAddedException extends Throwable { 4 | public SpotNotAddedException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/Address.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models; 2 | 3 | public class Address { 4 | private String country; 5 | private String state; 6 | private String city; 7 | private String zipCode; 8 | private String streetAddress; 9 | 10 | private Address(Builder builder) { 11 | country = builder.country; 12 | state = builder.state; 13 | city = builder.city; 14 | zipCode = builder.zipCode; 15 | streetAddress = builder.streetAddress; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "Address{" + 21 | "country='" + country + '\'' + 22 | ", state='" + state + '\'' + 23 | ", city='" + city + '\'' + 24 | ", zipCode='" + zipCode + '\'' + 25 | ", streetAddress='" + streetAddress + '\'' + 26 | '}'; 27 | } 28 | 29 | public static final class Builder { 30 | private String country; 31 | private String state; 32 | private String city; 33 | private String zipCode; 34 | private String streetAddress; 35 | 36 | public Builder() { 37 | } 38 | 39 | public Builder country(String val) { 40 | country = val; 41 | return this; 42 | } 43 | 44 | public Builder state(String val) { 45 | state = val; 46 | return this; 47 | } 48 | 49 | public Builder city(String val) { 50 | city = val; 51 | return this; 52 | } 53 | 54 | public Builder zipCode(String val) { 55 | zipCode = val; 56 | return this; 57 | } 58 | 59 | public Builder streetAddress(String val) { 60 | streetAddress = val; 61 | return this; 62 | } 63 | 64 | public Address build() { 65 | if(this.country == null) 66 | country = "India"; 67 | return new Address(this); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /src/com/justpark/models/DBObject.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models; 2 | 3 | import java.util.Objects; 4 | 5 | public abstract class DBObject { 6 | private final long uid; 7 | private static long NEW_UID = 0; 8 | 9 | public DBObject() { 10 | this.uid = NEW_UID++; 11 | } 12 | 13 | public long getUid() { 14 | return uid; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object o) { 19 | if (this == o) return true; 20 | if (o == null || getClass() != o.getClass()) return false; 21 | 22 | DBObject dbObject = (DBObject) o; 23 | return uid == dbObject.uid; 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hash(uid); 29 | } 30 | } -------------------------------------------------------------------------------- /src/com/justpark/models/Person.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models; 2 | 3 | import com.justpark.models.accounts.Account; 4 | 5 | public class Person extends DBObject { 6 | private String name; 7 | private Address address; 8 | private String phoneNumber; 9 | private Account account; 10 | 11 | private Person(Builder builder) { 12 | setName(builder.name); 13 | setAddress(builder.address); 14 | setPhoneNumber(builder.phoneNumber); 15 | account = builder.account; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "Person{" + 21 | "name='" + name + '\'' + 22 | '}'; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public Address getAddress() { 34 | return address; 35 | } 36 | 37 | public void setAddress(Address address) { 38 | this.address = address; 39 | } 40 | 41 | public String getPhoneNumber() { 42 | return phoneNumber; 43 | } 44 | 45 | public void setPhoneNumber(String phoneNumber) { 46 | this.phoneNumber = phoneNumber; 47 | } 48 | 49 | public Account getAccount() { 50 | return account; 51 | } 52 | 53 | public static final class Builder { 54 | private String name; 55 | private Address address; 56 | private String phoneNumber; 57 | private Account account; 58 | 59 | public Builder(String name) { 60 | this.name = name; 61 | } 62 | 63 | public Builder address(Address val) { 64 | address = val; 65 | return this; 66 | } 67 | 68 | public Builder phoneNumber(String val) { 69 | phoneNumber = val; 70 | return this; 71 | } 72 | 73 | public Builder account(Account val) { 74 | account = val; 75 | return this; 76 | } 77 | 78 | public Person build() { 79 | return new Person(this); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/com/justpark/models/accounts/Account.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.accounts; 2 | 3 | import com.justpark.models.DBObject; 4 | import com.justpark.models.Person; 5 | 6 | public abstract class Account extends DBObject { 7 | private String username; 8 | private String saltedPasswordHash; 9 | private final Person person; 10 | private AccountStatus status; 11 | 12 | public Account(String username, String saltedPasswordHash, Person person) { 13 | this.username = username; 14 | this.saltedPasswordHash = saltedPasswordHash; 15 | this.person = person; 16 | this.status = AccountStatus.ACTIVE; 17 | } 18 | 19 | public String getUsername() { 20 | return username; 21 | } 22 | 23 | public void setUsername(String username) { 24 | this.username = username; 25 | } 26 | 27 | public String getSaltedPasswordHash() { 28 | return saltedPasswordHash; 29 | } 30 | 31 | public void setSaltedPasswordHash(String saltedPasswordHash) { 32 | this.saltedPasswordHash = saltedPasswordHash; 33 | } 34 | 35 | public Person getPerson() { 36 | return person; 37 | } 38 | 39 | public AccountStatus getStatus() { 40 | return status; 41 | } 42 | 43 | public void setStatus(AccountStatus status) { 44 | this.status = status; 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /src/com/justpark/models/accounts/AccountStatus.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.accounts; 2 | 3 | public enum AccountStatus { 4 | ACTIVE, 5 | BANNED, 6 | DISABLED 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/accounts/Admin.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.accounts; 2 | 3 | import com.justpark.models.electronics.Electronics; 4 | import com.justpark.models.parking.Floor; 5 | import com.justpark.models.parking.Gate; 6 | import com.justpark.models.parking.spots.Spot; 7 | import com.justpark.models.Person; 8 | 9 | public class Admin extends Account { 10 | public Admin(String username, String saltedPasswordHash, Person person) { 11 | super(username, saltedPasswordHash, person); 12 | } 13 | 14 | void addFloor(Floor floor) { 15 | 16 | } 17 | void removeFloor(Floor floor) { 18 | 19 | } 20 | void modifyFloor(Floor floor) { 21 | 22 | } 23 | 24 | void addGate(Gate gate) { 25 | 26 | } 27 | void removeGate(Gate gate) { 28 | 29 | } 30 | void modifyGate(Gate gate) { 31 | 32 | } 33 | 34 | void addSpot(Floor floor, Spot spot) { 35 | 36 | } 37 | void removeSpot(Floor floor, Spot spot) { 38 | 39 | } 40 | void modifySpot(Floor floor, Spot spot) { 41 | 42 | } 43 | 44 | void addElectronics(Floor floor, Electronics panel) { 45 | 46 | } 47 | void removeElectronics(Floor floor, Electronics panel) { 48 | 49 | } 50 | void modifyElectronics(Floor floor, Electronics panel) { 51 | 52 | } 53 | 54 | void addAttendant(Floor floor, Attendant attendant) { 55 | 56 | } 57 | void removeAttendant(Floor floor, Attendant attendant) { 58 | 59 | } 60 | void modifyAttendant(Floor floor, Attendant attendant) { 61 | 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/com/justpark/models/accounts/Attendant.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.accounts; 2 | 3 | import com.justpark.models.parking.Ticket; 4 | import com.justpark.models.parking.interfaces.IssuesTicket; 5 | import com.justpark.models.parking.interfaces.PaymentEnabled; 6 | import com.justpark.models.Person; 7 | 8 | public class Attendant extends Account implements IssuesTicket, PaymentEnabled { 9 | public Attendant(String username, String saltedPasswordHash, Person person) { 10 | super(username, saltedPasswordHash, person); 11 | } 12 | 13 | @Override 14 | public Ticket giveTicket() { 15 | return null; 16 | } 17 | 18 | @Override 19 | public void processTicket(Ticket ticket) { 20 | 21 | } 22 | 23 | @Override 24 | public void processPayment() { 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/justpark/models/accounts/Customer.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.accounts; 2 | 3 | import com.justpark.models.parking.Ticket; 4 | import com.justpark.models.Person; 5 | 6 | public class Customer extends Account { 7 | public Customer(String username, String saltedPasswordHash, Person person) { 8 | super(username, saltedPasswordHash, person); 9 | } 10 | 11 | public Ticket getTicket() { 12 | return null; 13 | } 14 | 15 | public void payForTicket(Ticket ticket) { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/justpark/models/electronics/AutoExitPanel.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.electronics; 2 | 3 | import com.justpark.models.parking.Ticket; 4 | import com.justpark.models.parking.interfaces.PaymentEnabled; 5 | 6 | public class AutoExitPanel extends Electronics implements PaymentEnabled { 7 | @Override 8 | public void processTicket(Ticket ticket) { 9 | 10 | } 11 | 12 | @Override 13 | public void processPayment() { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/justpark/models/electronics/ChargingPanel.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.electronics; 2 | 3 | public class ChargingPanel extends Electronics { 4 | void connectCharger() { 5 | 6 | } 7 | 8 | void disconnectCharger() { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/justpark/models/electronics/CustomerInfoPortal.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.electronics; 2 | 3 | import com.justpark.models.parking.Ticket; 4 | import com.justpark.models.parking.interfaces.PaymentEnabled; 5 | 6 | public class CustomerInfoPortal extends Electronics implements PaymentEnabled { 7 | @Override 8 | public void processTicket(Ticket ticket) { 9 | 10 | } 11 | 12 | @Override 13 | public void processPayment() { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/justpark/models/electronics/DisplayBoard.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.electronics; 2 | 3 | import com.justpark.models.parking.interfaces.HasDisplay; 4 | 5 | public class DisplayBoard extends Electronics implements HasDisplay { 6 | 7 | @Override 8 | public void showMessage(String message) { 9 | System.out.println(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/justpark/models/electronics/Electronics.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.electronics; 2 | 3 | import com.justpark.models.DBObject; 4 | 5 | public abstract class Electronics extends DBObject { 6 | private String invoice; 7 | private String modelNumber; 8 | private String serialNumber; 9 | 10 | public String getInvoice() { 11 | return invoice; 12 | } 13 | 14 | public void setInvoice(String invoice) { 15 | this.invoice = invoice; 16 | } 17 | 18 | public String getModelNumber() { 19 | return modelNumber; 20 | } 21 | 22 | public void setModelNumber(String modelNumber) { 23 | this.modelNumber = modelNumber; 24 | } 25 | 26 | public String getSerialNumber() { 27 | return serialNumber; 28 | } 29 | 30 | public void setSerialNumber(String serialNumber) { 31 | this.serialNumber = serialNumber; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/justpark/models/electronics/EntrancePanel.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.electronics; 2 | 3 | import com.justpark.models.parking.Ticket; 4 | import com.justpark.models.parking.interfaces.HasDisplay; 5 | import com.justpark.models.parking.interfaces.IssuesTicket; 6 | 7 | public class EntrancePanel extends Electronics implements HasDisplay, IssuesTicket { 8 | 9 | @Override 10 | public void showMessage(String message) { 11 | 12 | } 13 | 14 | @Override 15 | public Ticket giveTicket() { 16 | return null; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/Floor.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking; 2 | 3 | import com.justpark.exceptions.MalformedVehicleException; 4 | import com.justpark.exceptions.SpotAlreadyFreeException; 5 | import com.justpark.exceptions.SpotAlreadyOccupiedException; 6 | import com.justpark.exceptions.SpotNotAddedException; 7 | import com.justpark.models.electronics.CustomerInfoPortal; 8 | import com.justpark.models.electronics.DisplayBoard; 9 | import com.justpark.models.parking.spots.Spot; 10 | import com.justpark.models.parking.spots.SpotStatus; 11 | import com.justpark.models.parking.spots.SpotType; 12 | import com.justpark.models.vehicles.Vehicle; 13 | import com.justpark.models.vehicles.VehicleType; 14 | 15 | import java.util.*; 16 | 17 | public class Floor { 18 | private CustomerInfoPortal customerInfoPortal; 19 | private Map> freeSpots; 20 | private Map> occupiedSpots; 21 | private DisplayBoard displayBoard; 22 | private String name; 23 | 24 | public Floor(String name) { 25 | setName(name); 26 | displayBoard = new DisplayBoard(); 27 | freeSpots = new HashMap<>(); 28 | occupiedSpots = new HashMap<>(); 29 | customerInfoPortal = new CustomerInfoPortal(); 30 | } 31 | 32 | private void populateMap(SpotType type) { 33 | if(!freeSpots.containsKey(type)) 34 | freeSpots.put(type, new HashSet<>()); 35 | if(!occupiedSpots.containsKey(type)) 36 | occupiedSpots.put(type, new HashSet<>()); 37 | } 38 | 39 | public void addSpot(Spot spot) throws SpotAlreadyOccupiedException { 40 | populateMap(spot.getType()); 41 | 42 | if (!spot.getStatus().equals(SpotStatus.FREE) || occupiedSpots.get(spot.getType()).contains(spot)) 43 | throw new SpotAlreadyOccupiedException("Can't move " + spot.toString() + " because it is occupied!"); 44 | freeSpots.get(spot.getType()).add(spot); 45 | } 46 | 47 | public synchronized void park(Spot spot, Vehicle vehicle) throws MalformedVehicleException, SpotAlreadyOccupiedException, SpotNotAddedException { 48 | populateMap(spot.getType()); 49 | if(!freeSpots.get(spot.getType()).contains(spot)) 50 | throw new SpotNotAddedException("Spot must be added to floor before it can be parked in"); 51 | spot.park(vehicle); 52 | freeSpots.get(spot.getType()).remove(spot); 53 | occupiedSpots.get(spot.getType()).add(spot); 54 | updateDisplayBoard(); 55 | } 56 | 57 | public synchronized Vehicle unPark(Spot spot) throws SpotAlreadyFreeException, SpotNotAddedException { 58 | populateMap(spot.getType()); 59 | if(!occupiedSpots.get(spot.getType()).contains(spot)) 60 | throw new SpotNotAddedException("Spot must be added to floor before it can be unparked."); 61 | Vehicle vehicle = spot.unPark(); 62 | occupiedSpots.get(spot.getType()).remove(spot); 63 | freeSpots.get(spot.getType()).add(spot); 64 | updateDisplayBoard(); 65 | return vehicle; 66 | } 67 | 68 | private void updateDisplayBoard() { 69 | StringBuilder message = new StringBuilder(); 70 | message.append(this.toString()).append("\n"); 71 | for(SpotType type: freeSpots.keySet()) { 72 | Set spots = freeSpots.get(type); 73 | message.append("\n").append(type.toString()).append(": "); 74 | if(spots.size() == 0) 75 | message.append("No free spots :("); 76 | else 77 | message.append(spots.iterator().next().toString()); 78 | } 79 | displayBoard.showMessage(message.toString()); 80 | } 81 | 82 | 83 | public String getName() { 84 | return name; 85 | } 86 | 87 | public void setName(String name) { 88 | this.name = name; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/Gate.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking; 2 | 3 | import com.justpark.models.electronics.AutoExitPanel; 4 | import com.justpark.models.DBObject; 5 | import com.justpark.models.accounts.Attendant; 6 | import com.justpark.models.parking.interfaces.PaymentEnabled; 7 | 8 | public class Gate extends DBObject implements PaymentEnabled { 9 | private GateType type; 10 | private String gateName; 11 | private Attendant attendant; 12 | private AutoExitPanel exitPanel; 13 | 14 | void open() { 15 | 16 | } 17 | 18 | void close() { 19 | 20 | } 21 | 22 | void getTicket() { 23 | 24 | } 25 | 26 | @Override 27 | public void processTicket(Ticket ticket) { 28 | 29 | } 30 | 31 | @Override 32 | public void processPayment() { 33 | 34 | } 35 | 36 | public GateType getType() { 37 | return type; 38 | } 39 | 40 | public void setType(GateType type) { 41 | this.type = type; 42 | } 43 | 44 | public String getGateName() { 45 | return gateName; 46 | } 47 | 48 | public void setGateName(String gateName) { 49 | this.gateName = gateName; 50 | } 51 | 52 | public Attendant getAttendant() { 53 | return attendant; 54 | } 55 | 56 | public void setAttendant(Attendant attendant) { 57 | this.attendant = attendant; 58 | } 59 | 60 | public AutoExitPanel getExitPanel() { 61 | return exitPanel; 62 | } 63 | 64 | public void setExitPanel(AutoExitPanel exitPanel) { 65 | this.exitPanel = exitPanel; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/GateType.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking; 2 | 3 | public enum GateType { 4 | ENTRANCE, 5 | EXIT, 6 | INACTIVE 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/GroundFloor.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking; 2 | 3 | import com.justpark.models.electronics.EntrancePanel; 4 | 5 | public class GroundFloor extends Floor { 6 | private EntrancePanel entrancePanel; 7 | 8 | public EntrancePanel getEntrancePanel() { 9 | return entrancePanel; 10 | } 11 | 12 | public void setEntrancePanel(EntrancePanel entrancePanel) { 13 | this.entrancePanel = entrancePanel; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/ParkingLot.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking; 2 | 3 | import com.justpark.models.Address; 4 | 5 | import java.util.List; 6 | 7 | public class ParkingLot { 8 | private List floors; 9 | private List gates; 10 | private Address address; 11 | 12 | public Address getAddress() { 13 | return address; 14 | } 15 | 16 | public void setAddress(Address address) { 17 | this.address = address; 18 | } 19 | 20 | public List getFloors() { 21 | return floors; 22 | } 23 | 24 | public void setFloors(List floors) { 25 | this.floors = floors; 26 | } 27 | 28 | public List getGates() { 29 | return gates; 30 | } 31 | 32 | public void setGates(List gates) { 33 | this.gates = gates; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/Ticket.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public class Ticket { 6 | private LocalDateTime issued; 7 | private TicketStatus ticketStatus; 8 | 9 | public LocalDateTime getIssued() { 10 | return issued; 11 | } 12 | 13 | public void setIssued(LocalDateTime issued) { 14 | this.issued = issued; 15 | } 16 | 17 | public TicketStatus getTicketStatus() { 18 | return ticketStatus; 19 | } 20 | 21 | public void setTicketStatus(TicketStatus ticketStatus) { 22 | this.ticketStatus = ticketStatus; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/TicketStatus.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking; 2 | 3 | public enum TicketStatus { 4 | ACTIVE, 5 | PAID, 6 | CANCELLED 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/interfaces/HasDisplay.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.interfaces; 2 | 3 | public interface HasDisplay { 4 | void showMessage(String message); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/interfaces/IssuesTicket.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.interfaces; 2 | 3 | import com.justpark.models.parking.Ticket; 4 | 5 | public interface IssuesTicket { 6 | public Ticket giveTicket(); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/interfaces/PaymentEnabled.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.interfaces; 2 | 3 | import com.justpark.models.parking.Ticket; 4 | 5 | public interface PaymentEnabled { 6 | public void processTicket(Ticket ticket); 7 | public void processPayment(); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/spots/CompactSpot.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.spots; 2 | 3 | public class CompactSpot extends Spot { 4 | public CompactSpot() { 5 | super(SpotType.COMPACT); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/spots/ElectricSpot.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.spots; 2 | 3 | import com.justpark.models.electronics.ChargingPanel; 4 | 5 | public class ElectricSpot extends Spot { 6 | private ChargingPanel chargingPanel; 7 | 8 | public ElectricSpot() { 9 | super(SpotType.ELECTRIC); 10 | } 11 | 12 | public ChargingPanel getChargingPanel() { 13 | return chargingPanel; 14 | } 15 | 16 | public void setChargingPanel(ChargingPanel chargingPanel) { 17 | this.chargingPanel = chargingPanel; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/spots/HandicappedSpot.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.spots; 2 | 3 | public class HandicappedSpot extends Spot { 4 | public HandicappedSpot() { 5 | super(SpotType.HANDICAPPED); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/spots/LargeSpot.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.spots; 2 | 3 | public class LargeSpot extends Spot { 4 | public LargeSpot(SpotType type) { 5 | super(SpotType.LARGE); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/spots/MotorcycleSpot.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.spots; 2 | 3 | public class MotorcycleSpot extends Spot { 4 | public MotorcycleSpot() { 5 | super(SpotType.MOTORCYCLE); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/spots/Spot.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.spots; 2 | 3 | import com.justpark.exceptions.MalformedVehicleException; 4 | import com.justpark.exceptions.SpotAlreadyFreeException; 5 | import com.justpark.exceptions.SpotAlreadyOccupiedException; 6 | import com.justpark.models.DBObject; 7 | import com.justpark.models.vehicles.Vehicle; 8 | 9 | public abstract class Spot extends DBObject { 10 | private final SpotType type; 11 | private SpotStatus status; 12 | private Vehicle vehicle; 13 | 14 | public Spot(SpotType type) { 15 | this.type = type; 16 | } 17 | 18 | public SpotType getType() { 19 | return type; 20 | } 21 | 22 | public SpotStatus getStatus() { 23 | return status; 24 | } 25 | 26 | public void setStatus(SpotStatus status) { 27 | this.status = status; 28 | } 29 | 30 | public void park(Vehicle vehicle) throws SpotAlreadyOccupiedException, MalformedVehicleException { 31 | if (!status.equals(SpotStatus.FREE)) 32 | throw new SpotAlreadyOccupiedException(this.toString() + " is already occupied!"); 33 | if (!vehicle.getType().getFitsIn().contains(this.getType())) 34 | throw new MalformedVehicleException(vehicle.getType().toString() + " doesn't fit in " + this.toString()); 35 | this.vehicle = vehicle; 36 | status = SpotStatus.OCCUPIED; 37 | } 38 | 39 | public Vehicle unPark() throws SpotAlreadyFreeException { 40 | if (!status.equals(SpotStatus.OCCUPIED)) 41 | throw new SpotAlreadyFreeException(this.toString() + " is already free!"); 42 | Vehicle vehicle = this.vehicle; 43 | this.vehicle = null; 44 | status = SpotStatus.FREE; 45 | return vehicle; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "Spot{" + 51 | "type=" + type + 52 | ", status=" + status + 53 | ", vehicle=" + vehicle + 54 | '}'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/spots/SpotStatus.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.spots; 2 | 3 | public enum SpotStatus { 4 | FREE, 5 | OCCUPIED, 6 | DISABLED 7 | } 8 | -------------------------------------------------------------------------------- /src/com/justpark/models/parking/spots/SpotType.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.parking.spots; 2 | 3 | import com.justpark.models.vehicles.VehicleType; 4 | 5 | import java.util.List; 6 | 7 | public enum SpotType { 8 | COMPACT, 9 | LARGE, 10 | HANDICAPPED, 11 | MOTORCYCLE, 12 | ELECTRIC 13 | } 14 | -------------------------------------------------------------------------------- /src/com/justpark/models/vehicles/Car.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.vehicles; 2 | 3 | 4 | public class Car extends Vehicle { 5 | public Car() { 6 | super(VehicleType.CAR); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/justpark/models/vehicles/Electric.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.vehicles; 2 | 3 | 4 | public class Electric extends Vehicle { 5 | public Electric() { 6 | super(VehicleType.ELECTRIC); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/justpark/models/vehicles/Motorcycle.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.vehicles; 2 | 3 | 4 | public class Motorcycle extends Vehicle { 5 | public Motorcycle() { 6 | super(VehicleType.MOTORCYCLE); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/justpark/models/vehicles/Truck.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.vehicles; 2 | 3 | 4 | public class Truck extends Vehicle { 5 | public Truck() { 6 | super(VehicleType.TRUCK); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/justpark/models/vehicles/Van.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.vehicles; 2 | 3 | 4 | public class Van extends Vehicle { 5 | public Van() { 6 | super(VehicleType.VAN); 7 | } 8 | } 9 | 10 | 11 | // pragy@interviewbit.com // flock 12 | // academy@interviewbit.com 13 | -------------------------------------------------------------------------------- /src/com/justpark/models/vehicles/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.vehicles; 2 | 3 | import com.justpark.models.DBObject; 4 | import com.justpark.models.parking.Ticket; 5 | 6 | public abstract class Vehicle extends DBObject { 7 | private String plateNumber; 8 | private String color; 9 | private final VehicleType type; 10 | private Ticket ticket; 11 | 12 | public Vehicle(VehicleType type) { 13 | this.type = type; 14 | } 15 | 16 | public String getPlateNumber() { 17 | return plateNumber; 18 | } 19 | 20 | public void setPlateNumber(String plateNumber) { 21 | this.plateNumber = plateNumber; 22 | } 23 | 24 | public String getColor() { 25 | return color; 26 | } 27 | 28 | public void setColor(String color) { 29 | this.color = color; 30 | } 31 | 32 | public VehicleType getType() { 33 | return type; 34 | } 35 | 36 | public Ticket showTicket() { 37 | return ticket; 38 | } 39 | 40 | public void assignTicket(Ticket ticket) { 41 | this.ticket = ticket; 42 | } 43 | } -------------------------------------------------------------------------------- /src/com/justpark/models/vehicles/VehicleType.java: -------------------------------------------------------------------------------- 1 | package com.justpark.models.vehicles; 2 | 3 | import com.justpark.models.parking.spots.SpotType; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | public enum VehicleType { 9 | CAR(Arrays.asList(SpotType.COMPACT, SpotType.LARGE)), 10 | TRUCK(Arrays.asList(SpotType.LARGE)), 11 | VAN(Arrays.asList(SpotType.LARGE)), 12 | MOTORCYCLE(Arrays.asList(SpotType.MOTORCYCLE, SpotType.COMPACT, SpotType.LARGE)), 13 | ELECTRIC(Arrays.asList(SpotType.ELECTRIC)); 14 | 15 | private final List fitsIn; 16 | 17 | VehicleType(List fitsIn) { 18 | this.fitsIn = fitsIn; 19 | } 20 | 21 | public List getFitsIn() { 22 | return fitsIn; 23 | } 24 | } 25 | --------------------------------------------------------------------------------