Advertisement
IrinaIgnatova

examSoftUni Parking-classParking

Dec 16th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by Fernflower decompiler)
  4. //
  5.  
  6. package softUniParking;
  7.  
  8. import java.util.HashMap;
  9. import java.util.Iterator;
  10. import java.util.List;
  11. import java.util.Map;
  12.  
  13. public class Parking {
  14.     private Map<String, Car> cars = new HashMap();
  15.     private int capacity;
  16.  
  17.     public Parking(int capacity) {
  18.         this.capacity = capacity;
  19.     }
  20.  
  21.     public String addCar(Car car) {
  22.         if (this.cars.containsKey(car.getRegistrationNumber())) {
  23.             return "Car with that registration number, already exists!";
  24.         } else if (this.cars.size() >= this.capacity) {
  25.             return "Parking is full!";
  26.         } else {
  27.             this.cars.putIfAbsent(car.getRegistrationNumber(), car);
  28.             String var10000 = car.getMake();
  29.             return "Successfully added new car " + var10000 + " " + car.getRegistrationNumber();
  30.         }
  31.     }
  32.  
  33.     public String removeCar(String registrationNumber) {
  34.         if (!this.cars.containsKey(registrationNumber)) {
  35.             return "Car with that registration number, doesn't exists!";
  36.         } else {
  37.             this.cars.remove(registrationNumber);
  38.             return "Successfully removed " + registrationNumber;
  39.         }
  40.     }
  41.  
  42.     public Car getCar(String registrationNumber) {
  43.         return (Car)this.cars.get(registrationNumber);
  44.     }
  45.  
  46.     public void removeSetOfRegistrationNumber(List<String> registrationNumbers) {
  47.         Iterator var2 = registrationNumbers.iterator();
  48.  
  49.         while(var2.hasNext()) {
  50.             String registrationNumber = (String)var2.next();
  51.             this.removeCar(registrationNumber);
  52.         }
  53.  
  54.     }
  55.  
  56.     public int getCount() {
  57.         return this.cars.size();
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement