/* * EzPassLocation.java * * Created on March 3, 2005, 8:40 AM * Originally Created on April 27, 2003, 7:46 PM */ package ezpassassign; /** * * @author Mike */ public class EzPassLocation { private String name = ""; private String city = ""; private String state = "PA"; private String highway = "NJ Turnpike"; private int numLanes = 3; private char direction = 'E'; /** Creates a new instance of EzPassLocation - with defaults for everything */ public EzPassLocation() { System.out.println("In EZPL constructor #1"); } /** Creates a new instance of EzPassLocation - with given name and defaults for everything else */ public EzPassLocation(String nam) { System.out.println("In EZPL constructor #2"); name = nam; } /** Creates a new instance of EzPassLocation - with given name, city and state and defaults for everything else */ public EzPassLocation(String nam, String cty, String stat) { System.out.println("In EZPL constructor #3"); name = nam; city = cty; state = stat; } /** Creates a new instance of EzPassLocation - with all info given */ public EzPassLocation(String nam, String cty, String stat, String hwy, int num, char dir) { System.out.println("In EZPL constructor #4"); name = nam; city = cty; state = stat; highway = hwy; setNumLanes(num); setDirection(dir); } /** * report ez pass location name */ public String getName() { return name; } /** * report ez pass location city */ public String getCity() { return city; } /** * report ez pass location state */ public String getState() { return state; } /** * report ez pass location highway */ public String getHighway() { return highway; } /** * report ez pass location number of lanes */ public int getNumLanes() { return numLanes; } /** * report ez pass location direction */ public int getDirection() { return direction; } /** * change ez pass location name */ public void setName(String nam) { name = nam; } /** * change ez pass location city */ public void setCity(String cty) { city = city; } /** * change ez pass location state. Right now we can't validate, need list of states */ public boolean setState(String stat) { state = stat; return true; } /** * change ez pass location highway. */ public boolean setHighway(String hwy) { highway = hwy; return true; } /** * change ez pass location number of lanes. * If negative number - reject and return false. * Number of lanes will remain what it was. */ public boolean setNumLanes(int num) { if (num < 1) { // gotta have at least one lane return false; } else { numLanes = num; return true; } } /** * change ez pass location direction - N/S E/W. * If invalid - reject and return false. * Direction will remain as it was. */ public boolean setDirection(char dir) { if ((dir == 'N') || (dir == 'n')) { direction = 'N'; } else if ((dir == 'S') || (dir == 's')) { direction = 'S'; } else if ((dir == 'E') || (dir == 'e')) { direction = 'E'; } else if ((dir == 'W') || (dir == 'w')) { direction = 'W'; } else { return false; } // not rejected - was ok return true; } /** * report if invoking Location has same contents as passed Location */ public boolean equals(Object obj) { if (!(obj instanceof EzPassLocation)) { // 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 ((name.equals(toCompare.getName())) && (city == toCompare.getCity()) && (state == toCompare.getState()) && (highway == toCompare.getHighway()) && (numLanes == toCompare.getNumLanes()) && (direction == toCompare.getDirection()) ) { return true; } else { return false; } } } /** * report ez pass location direction - as a string "North" "South" etc. * Only have to handle upper case since setDirection controls values. */ public String getDirectionString() { String answ = ""; switch (direction) { case 'N': answ = "North"; break; case 'S': answ = "South"; break; case 'E': answ = "East "; break; case 'W': answ = "West "; break; default: // should never get here because setDirection controls values answ = "OOOPS"; } return answ; } /** * give string representation for a Location */ public String toString() { String res = ""; res += " Name: " + getName(); res += " City: " + getCity(); res += " State: " + getState(); res += " Highway: " + getHighway(); res += " Direction: " + getDirectionString(); res += " Lanes: " + getNumLanes(); return res; } }