import java.util.HashSet; import java.util.Set; /******************************************************************************* * Třída PrivateCar * * @author Tomáš Pitner * @version 1.00, 10.8.2005 */ public class PrivateCar extends Car { private int seatsCount; private Set crew; /*************************************************************************** * */ public PrivateCar(String l, int s) { super(l); seatsCount = s; crew = new HashSet(); } /*************************************************************************** * Usaď osobu * * @param p Osoba * @throws Ex Popis vyhazovane vyjimky */ public void getOn(Person p) throws NotEnoughSeatsException { if(crew.size() < seatsCount) { crew.add(p); } else { throw new NotEnoughSeatsException(this); } } /*************************************************************************** * Vystup osobu * * @param p Osoba * @throws Ex Popis vyhazovane vyjimky */ public void getOff(Person p) throws NotInTheCarException { if(crew.contains(p)) { crew.remove(p); } else { throw new NotInTheCarException(p, this); } } /*************************************************************************** * Zobraz posadku auta * */ public void listCrew() { int i = 1; for(Person p: crew) { System.out.println("Person "+ i + ". " + p); i++; } } public String toString() { return "Private car "+ getLabel() + " with " + seatsCount + " seat(s)"; } public String asRecord() { return "Private car " + getLabel() +" "+seatsCount; } }