1603. 设计停车系统

  1. class ParkingSystem {
  2. private int big;
  3. private int medium;
  4. private int small;
  5. public ParkingSystem(int big, int medium, int small) {
  6. this.big = big;
  7. this.medium = medium;
  8. this.small = small;
  9. }
  10. public boolean addCar(int carType) {
  11. switch (carType) {
  12. case 1:
  13. return --big >= 0;
  14. case 2:
  15. return --medium >= 0;
  16. case 3:
  17. return --small >= 0;
  18. default:
  19. return false;
  20. }
  21. }
  22. }
  23. /**
  24. * Your ParkingSystem object will be instantiated and called as such:
  25. * ParkingSystem obj = new ParkingSystem(big, medium, small);
  26. * boolean param_1 = obj.addCar(carType);
  27. */