/** * A StudentCardFactory is a CardFactory that creates cards for a * student. **/ public class StudentCardFactory extends CardFactory { private static final int CARD_COST = 25; protected static StudentCardFactory cardFactory = new StudentCardFactory(); private StudentCardFactory() { //suppress default no-arg constructor } /** * @return an instance of CardFactory. this class cannot be * instantiated directly; instances can ONLY be acquired through * this method. */ public StudentCardFactory getInstance() { return this.cardFactory; } /** * A factory method to produce a new card. * * @throws NotAStudentException if name and idNumber do not * refer to a student * @return a new Card for the person with name 'name' and id number * 'idNumber', that gives access to the buildings in privileges. * The card is a student card -- the background is purple, and * "Student" is printed on the card. **/ public Card createCard(String name, String idNumber) throws NotAStudentException { BuildingID dorm = null; try { dorm = CardOffice.getDorm(idNumber); } catch (NotAStudentException e) { throw e; } List accessPrivileges = new ArrayList(); if (dorm != null) { AccessPrivilege dormPriv = CardOffice.getBuildingAccess(idNumber, dorm); accessPrivileges.add(dormPriv); } chargeBursar(CARD_COST); return new Card(name, idNumber, CARD_COLOR, "Student", accessPrivileges); } }