/* * Passenger.java * * Created on January 24, 2006, 3:42 PM * * I'd be tempted to extend a Person class, except we're aways away from * inheritance * * I'm going to model this as a ticket contains a passenger instead of a passenger * holds ticket(s) * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package airline; import edu.lasalle.redmond.IDs.*; /** * * @author redmond */ public class Passenger { private Id customerID; private String lastName; private String firstName; private String streetAddr; private String city; private String state; private String zip; private String freqFlyerType; // for now, choices are: none, regular, preferred, or premium private int freqFlyerPts = 0; private Airport homeAirport; // constants private static final int UPGRADEPOINTS = 10000; private static final int REGIONALTRIPPOINTS = 20000; private static final int CROSSCOUNTRYTRIPPOINTS = 30000; private static final int INTERNATIONALTRIPPOINTS = 50000; /** * Creates a new instance of Passenger. Without any info, can only assign a random * 5 digit customer ID */ public Passenger() { customerID = new Id(5); // create a random 5 digit id lastName = "unknown"; firstName = "unknown"; streetAddr = "who knows"; city = "unknown"; state = "??"; zip = "000000000"; freqFlyerType = "regular"; homeAirport = new Airport(); } /** * Creates a new instance of Passenger - we only know their name. Their customerID * is randomly generated; the rest of the info is left unknown. */ public Passenger(String last, String first) { customerID = new Id(5); // create a random 5 digit id lastName = last; firstName = first; streetAddr = "who knows"; city = "unknown"; state = "??"; zip = "000000000"; freqFlyerType = "regular"; homeAirport = new Airport(); } /** * Creates a new instance of Passenger - we know their name and address. Their customerID * is randomly generated; */ public Passenger(String last, String first, String addr, String cty, String stat, String zp) { customerID = new Id(5); // create a random 5 digit id lastName = last; firstName = first; streetAddr = addr; city = cty; state = stat; zip = zp; freqFlyerType = "regular"; homeAirport = new Airport(); } /** * Creates a new instance of Passenger - we know their name and address and frequent flyer type. Their customerID * is randomly generated; */ public Passenger(String last, String first, String addr, String cty, String stat, String zp, String ffType) { customerID = new Id(5); // create a random 5 digit id lastName = last; firstName = first; streetAddr = addr; city = cty; state = stat; zip = zp; freqFlyerType = ffType; homeAirport = new Airport(); } /** * Creates a new instance of Passenger - we know their name and address and * frequent flyer type and home airport. Their customerID * is randomly generated; */ public Passenger(String last, String first, String addr, String cty, String stat, String zp, String ffType, Airport home) { customerID = new Id(5); // create a random 5 digit id lastName = last; firstName = first; streetAddr = addr; city = cty; state = stat; zip = zp; freqFlyerType = ffType; homeAirport = home; } /// inspectors /** * report customer id */ public Id getCustomerID () { return customerID; } /** * report last name */ public String getLastName() { return lastName; } /** * report first name */ public String getFirstName() { return firstName; } /** * report street address */ public String getStreetAddr() { return streetAddr; } /** * report city */ public String getCity() { return city; } /** * report state */ public String getState() { return state; } /** * report zip code */ public String getZip() { return zip; } /** * report frequent flyer type. Should move to enumerated type later */ public String getFreqFlyerType() { return freqFlyerType; } /** * report current number of frequent flyer miles */ public int getFreqFlyerPts () { return freqFlyerPts; } /** * report passenger's "home" airport */ public Airport gethomeAirport() { return homeAirport; } /// mutators - with mostly strings these won't be very interesting - but need them in case /// don't know everything we need to know when we first create the passenger /** * change customer ID. Should probably be stricter since we have the id class to rely * on. So far just check that it is the correct length (5) */ public boolean setCustomerID (Id custID) { // check that id is valid if (custID.getLength() == 5) { // check length - should also be able to check check digit if used customerID = custID; return true; } else { return false; } } /** * change passengers last name - hard to validate */ public void setLastName(String last) { lastName = last; } /** * change passengers first name - hard to validate */ public void setFirstName(String first) { firstName = first; } /** * change passengers street address - hard to validate */ public void setStreetAddr(String addr) { streetAddr = addr; } /** * change passengers city - hard to validate */ public void setCity(String cty) { city = cty; } /** * change passengers state - check length. returns false if not two chars. * Should do a lookup of possible values */ public boolean setState(String stat) { if (stat.length() == 2) { state = stat; // must be 2 char return true; } else { return false; } } /** * change passenger zip code. Only check length (5 or 9 acceptable) */ public boolean setZip(String zp) { if ((zp.length() == 5) || (zp.length() == 9)) { zip = zp; return true; } else { return false; } } /** * change frequent flyer type. Check for appropriate value (should be * enumberated type later. */ public boolean setFreqFlyerType(String fft) { if ( fft.equals("none") || fft.equals("regular") || fft.equals("preferred") || fft.equals("premium") ) { freqFlyerType = fft; return true; } else { return false; } } // maybe later use enumerated (none, regular, preferred, premium) /** * change number of frequent flyer points - should probably make private and have more controlled methods * So far, just check that points are positive - really need more careful checking */ public boolean setFreqFlyerPts (int pts) { if (pts > 0) { freqFlyerPts = pts; return true; } else { return false; } } // more controlled access to frequent flyer points /** * deduct number of points needed for a first class upgrade. * return false if not enough points in account. * Really should depend on frequent flyer type, but we don't have that yet */ public boolean deductUpgrade () { if (this.freqFlyerPts >= this.UPGRADEPOINTS) { freqFlyerPts -= UPGRADEPOINTS; return true; } else { return false; } } /** * deduct number of points needed for a short or regional trip * return false if not enough points in account. * Really should depend on frequent flyer type, but we don't have that yet */ public boolean deductRegionalTrip () { if (this.freqFlyerPts >= this.REGIONALTRIPPOINTS) { freqFlyerPts -= REGIONALTRIPPOINTS; return true; } else { return false; } } /** * deduct number of points needed for a cross country trip * return false if not enough points in account. * Really should depend on frequent flyer type, but we don't have that yet */ public boolean deductCrossCountryTrip () { if (this.freqFlyerPts >= this.CROSSCOUNTRYTRIPPOINTS) { freqFlyerPts -= CROSSCOUNTRYTRIPPOINTS; return true; } else { return false; } } /** * deduct number of points needed for an international trip * return false if not enough points in account. * Really should depend on frequent flyer type, but we don't have that yet */ public boolean deductInternationalTrip () { if (this.freqFlyerPts >= this.INTERNATIONALTRIPPOINTS) { freqFlyerPts -= INTERNATIONALTRIPPOINTS; return true; } else { return false; } } /** * add to number of frequent flyer points - given only number of points to add * So far, just check that points are positive - really need more careful checking */ public boolean addFreqFlyerPts (int pts) { if (pts > 0) { freqFlyerPts += pts; return true; } else { return false; } } /** * add to number of frequent flyer points - given a Route flown. * Don't know if there is validation that should be done. * I have mixed feeling about passenger depending on the existence of Route. */ public boolean addFreqFlyerPts (Route rt) { int milesToAdd = rt.getMiles(); freqFlyerPts += milesToAdd; return true; } /** * change passengers home airport. * Right now, can't validate - need Collection of airports - but it is * unclear if passenger class should depend on having that */ public boolean setHomeAirport(Airport home) { homeAirport =home; return true; } /** * converts route into a string represention. * Overrides Object version */ public String toString () { String res = ""; res += "ID: " + customerID.toShortString(); res += " Name: " + firstName + " " + lastName; res += " Addr: " + streetAddr + " " + city + ", " + state + " " + zip; res += " Airport: " + homeAirport.toShortString(); res += " Freq Flyer Type: " + freqFlyerType; res += " Miles Earned: " + freqFlyerPts; return res; } /** * Provide brief info about the passenger */ public String toShortString () { String res = ""; res += "ID: " + customerID.toShortString(); res += " Name: " + firstName + " " + lastName; res += " Freq Flyer Type: " + freqFlyerType; res += " Miles Earned: " + freqFlyerPts; return res; } }