package expedia; import java.util.Date; import type.lib.CreditCard; /** * A ticket. * * @author Franck van Breugel */ public class Ticket { private String from; private String to; private Date departing; private Date returning; private CreditCard card; /** * Initializes this ticket with the given data. * * @param from from which city to fly. * @param to to which city to fly. * @param departing date of departure. * @param returning date of return. */ public Ticket(String from, String to, Date departing, Date returning, CreditCard card) { this.setFrom(from); this.setTo(to); this.setDeparting(departing); this.setReturning(returning); this.setCard(card); } /** * Returns the from of this ticket. * * @return the from of this ticket. */ public String getFrom() { return this.from; } /** * Sets the from of this ticket to the given from. * * @param from the new from of this ticket. */ private void setFrom(String from) { this.from = from; } /** * Returns the to of this ticket. * * @return the to of this ticket. */ public String getTo() { return this.to; } /** * Sets the to of this ticket to the given to. * * @param to the new to of this ticket. */ private void setTo(String to) { this.to = to; } /** * Returns the departing of this ticket. * * @return the departing of this ticket. */ public Date getDeparting() { return new Date(this.departing.getTime()); } /** * Sets the departing of this Ticket to the given departing. * * @param departing the new departing of this Ticket. */ public void setDeparting(Date departing) { final double FEE = 300; if (this.departing == null || this.getCard().charge(FEE)) { this.departing = new Date(departing.getTime()); } } /** * Returns the returning of this ticket. * * @return the returning of this ticket. */ public Date getReturning() { return new Date(this.returning.getTime()); } /** * Sets the returning of this Ticket to the given returning. * * @param returning the new returning of this Ticket. */ public void setReturning(Date returning) { final double FEE = 600; if (this.returning == null || this.getCard().charge(FEE)) { this.returning = new Date(returning.getTime()); } } /** * Returns the card of this ticket. * * @return the card of this ticket. */ private CreditCard getCard() { return this.card; } /** * Sets the card of this ticket to the given card. * * @param card the new card of this ticket. */ private void setCard(CreditCard card) { this.card = card; } }