Refonte du repo
This commit is contained in:
45
src/TD8/parking/Parking.java
Normal file
45
src/TD8/parking/Parking.java
Normal file
@ -0,0 +1,45 @@
|
||||
package parking;
|
||||
import vehicule.Voiture;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Parking {
|
||||
int taille;
|
||||
HashMap<Integer, Voiture> parking = new HashMap<Integer, Voiture>();
|
||||
|
||||
public Parking(int nbplace, HashMap<Integer, Voiture> park) {
|
||||
taille = nbplace;
|
||||
parking = park;
|
||||
}
|
||||
public void garer(Voiture v, int place) throws IndexOutOfBoundsException, IllegalStateException{
|
||||
if(place>taille || place<0)
|
||||
throw new IndexOutOfBoundsException("Place inexistante");
|
||||
if(parking.get(place)==null) {
|
||||
parking.put(place, v);
|
||||
}else {
|
||||
throw new IllegalStateException("Place occup<75>");
|
||||
}
|
||||
}
|
||||
public Voiture liberer(int place) throws IndexOutOfBoundsException{
|
||||
Voiture voit = parking.get(place);
|
||||
parking.remove(place);
|
||||
return voit;
|
||||
}
|
||||
public int chercher(Voiture v) throws IllegalStateException {
|
||||
for (int i = 0; i < parking.size(); i++) {
|
||||
if(parking.get(i).equals(v)) {
|
||||
return i;
|
||||
}else {
|
||||
throw new IllegalStateException("Place inexistante");
|
||||
}
|
||||
}
|
||||
System.out.println("Voiture non pr<70>sente");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
for (int i = 0; i < parking.size()-1; i++) {
|
||||
System.out.println("Place : " + i + " Voiture " + parking.get(i));
|
||||
}
|
||||
return "Place : " + taille + " Voiture" + parking.get(taille);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user