daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Jun 25th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static ArrayList<Vehicle> al=new ArrayList<Vehicle>();
  2.     java.util.Iterator<Vehicle> itr= al.iterator();
  3.  
  4.     @SuppressWarnings("unchecked")
  5.     public boolean addVehicleToSlot(Vehicle vehicle) {
  6.         if((vehicle.slotNo<=0||vehicle.slotNo>40)&&(vehicle.getVehicleType()!="Car"
  7.                 ||vehicle.getVehicleType()!="Truck"||vehicle.getVehicleType()!="Two Wheeler")){
  8.             new InvalidSlotException("Slot alraedy allotted");
  9.             return false;
  10.         }
  11.         int iter=0;
  12.         int len=al.size();
  13.         if(len==0){
  14.             al.add(vehicle);
  15.             return true;
  16.         }
  17.         while(iter< len){
  18.             Vehicle veh=(Vehicle)itr.next();
  19.             if(veh.getSlotNo()==vehicle.getSlotNo()){
  20.                 new SlotNotFoundException("No slot allotted");
  21.                 return false;
  22.             }
  23.             else{
  24.                 al.add(vehicle);
  25.                 for(Vehicle vehi:al){
  26.                     System.out.println(al);
  27.                 }
  28.                 return true;
  29.             }
  30.         }
  31.         return false;
  32.     }
  33.    
  34. Vehicle v1=new Vehicle(o1,"ts75","Truck",37,48);
  35.     ParkingManagement p1=new ParkingManagement();
  36.     System.out.println(p1.addVehicleToSlot(v1));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top