Refonte du repo

This commit is contained in:
JunkJumper
2020-05-20 17:01:49 +02:00
parent 4962efbd17
commit 45f4d2dffe
165 changed files with 83943 additions and 84353 deletions

View 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);
}
}