/* * EzPassBridge.java * * Created on March 3, 2005, 8:43 AM * Originally Created on April 27, 2003, 7:52 PM */ package ezpassassign; import java.util.*; /** * * @author Mike */ public class EzPassBridge extends EzPassLocation { /** * price for a particular bridge */ private double price = 2.70; /** Creates a new instance of EzPassBridge - with defaults for everything*/ public EzPassBridge() { System.out.println("In bridge constructor #1"); } /** Creates a new instance of EzPassBridge - with name and defaults for everything else */ public EzPassBridge(String nam) { super(nam); System.out.println("In bridge constructor #2"); } /** Creates a new instance of EzPassBridge - with name and price given, defaults for everything else */ public EzPassBridge(String nam, double prc) { super(nam); System.out.println("In bridge constructor #3"); price = prc; } /** Creates a new instance of EzPassBridge - with name, city and state and price given, defaults for everything else */ public EzPassBridge(String nam, String cty, String stat, double prc) { super(nam,cty,stat); System.out.println("In bridge constructor #4"); price = prc; } /** Creates a new instance of EzPassBridge - with all info given */ public EzPassBridge(String nam, String cty, String stat, String hwy, int num, char dir, double prc) { super(nam,cty,stat,hwy,num,dir); System.out.println("In bridge constructor #5"); price = prc; } /** * report ez pass bridge price */ public double getPrice() { return price; } /** * report ez pass bridge price - alias since this is really core functionality * much more important than just an inspector - provide a very logical name for * the functionality * */ public double tollAmount() { return price; } /** * change ez pass bridge price. * If price is outside normal range (0.25 -> 10.00), reject and return false. * (based top of range on Chesapeake Bay Bridge Tunnel) * Existing price will remain. */ public boolean setPrice(double prc) { if ((prc < 0.25) || (prc > 10.00)) { // anything under a penny is impossible return false; } else { price = prc; return true; } } /** * debit a customer the price for this bridge. * Reduces the customer balance by the price for this bridge. * If the customer method throws an exception, we must handle it (and return false) * */ public boolean debit(EzPassCustomer cust) { System.out.println("In bridge debit"); try { // don't need return because that is only false if negative amount and // we have not made it possible for price to be negative cust.decreaseBalance(price); System.out.println("Cust: " + cust.getName() + " Bal: " + cust.getBalance()); return true; } catch (InsufficientFundsNonCreditException ex) { // don't bother with message, violation will explain // System.out.println("In catch block with: " + ex.getCustTakingFrom()); cust.sendViolation(); return false; } } /** * generate a string represnetation for a bridge */ public String toString() { String res = super.toString(); res += " Price: " + getPrice(); return res; } /** * determine if invoking bridge has the same contents as the passed bridge */ public boolean equals(Object obj) { if (!(obj instanceof EzPassBridge)) { // can't be equal if not the same typ object return false; } else { EzPassLocation toCompare = (EzPassLocation) obj; // if all data equal then objects equal if (super.equals(toCompare) && price == ((EzPassBridge) toCompare).getPrice() ) { return true; } else { return false; } } } }