/** * Contains the detailed information about an address. * @author Khong Lovan * @author Elias Vafiadis * @author Anthony Nakaar * @author Wanlin Liu * version 1.0 of October, 1999 */ public class StreetAddress{ //+--------+------------------------------------------------------------ //| Fields | //+--------+ /** Number of the house, street name ,apartment number, etc. */ String street; /** City name.*/ String city; /** State name. */ String state; /** Country name. */ String country; /** Zip number. */ String zip; /** Telephone number. */ String phoneNum; //+--------------+--------------------------------------------------------- //| Constructors | //+--------------+ /** * this constructor takes 3 strings, street name inclucing number of the * house, city name and the state name. and builds a new StreetAddress */ public StreetAddress(String streetN, String cityName, String stateName) { street = streetN; city = cityName; state = stateName; } /** * this constructor takes 4 strings, street name inclucing number of the * house, city name, the state name and the country name. * and builds a new StreetAddress */ public StreetAddress(String streetN, String cityName, String stateName, String countryName) { street = streetN; city = cityName; state = stateName; country = countryName; }// /** * this constructor takes 6 strings, street name inclucing number of the * house, city name, the state name, the country name, the zip code and * the phone number. * and builds a new StreetAddress */ public StreetAddress(String streetN, String cityName, String stateName, String countryName, String postCode, String foneN) { street = streetN; city = cityName; state = stateName; country = countryName; zip = postCode; phoneNum = foneN; }// /** * Create a new instance of class StreetAddress with the product of the toString * method of the StreetAddress class. * @exception if the string is not convertible. */ public StreetAddress(String allInfo) throws Exception{ // Get the substring "street" from the string "allinfo" */ int comma = allInfo.indexOf(","); if(comma== -1){ throw new Exception("Invalid"); }//if else{ this.street = allInfo.substring(0,comma); }//else //Cut the substring "street" from the string "allinfo" and get the substring city */ String str = allInfo.substring(comma+1); comma = str.indexOf(","); if(comma == -1){ throw new Exception("Invalid"); }//if else{ this.city = str.substring(0,comma); }//else //Cut the substring "street" from the string "allinfo" and get the substring "state" */ str = str.substring(comma+1); comma = str.indexOf(","); if(comma== -1){ throw new Exception("Invalid"); }//if else{ this.state = str.substring(0, comma); }//else //Cut the substring "state" from the string "allinfo" and get the substring "city" */ str = str.substring(comma+1); comma = str.indexOf(","); if(comma== -1){ throw new Exception("Invalid"); }//if else{ this.country = str.substring(0,comma); }//else //Cut the substring "city" from the string "allinfo" and get the substring "zip" */ str = str.substring(comma+1); comma = str.indexOf(","); if(comma== -1){ throw new Exception("Invalid"); }//if else{ this.zip = str.substring(0,comma); }//else //Cut the substring "zip" from the string "allinfo" and get the substring "phoneNum" */ str = str.substring(comma+1); comma = str.indexOf(","); if(comma== -1){ throw new Exception("Invalid"); }//if else{ this.phoneNum = str.substring(comma+1); }//else }//StreetAddress() /** * Purpose: To obtain the city of the user's address. * Parameter: No parameters needed. * Pre: city has been initialized * Post:The value of the city is not changed * Return: the string value of the city * errors: Throws no exceptions */ public String getCity() { return this.city; }//getCity() /** * Purpose: To obtain the state of the user's address. * Parameter: No parameters needed. * Pre: statet has been initialized * Post:The value of the state is not changed * Return: the string value of the state * errors: Throws no exceptions */ public String getState() { return this.state; }//getState() /** * Purpose: To obtain the country of the user's address. * Parameter: No parameters needed. * Pre: country has been initialized * Post:The value of the country is not changed * Return: the string value of the country * errors: Throws no exceptions */ public String getCountry() { return this.country; }//getCountry() /** * Purpose: To obtain the zipcode of the user's address. * Parameter: No parameters needed. * Pre: zipcode has been initialized * Post:The value of the zipcode is not changed * Return: the string value of the zipcode * errors: Throws no exceptions */ public String getZip() { return this.zip; }//getZip() /** * Purpose: To obtain the phone number of the user's address. * Parameter: No parameters needed. * Pre: phone number has been initialized * Post:The value of the phone number is not changed * Return: the string value of the phone number * errors: Throws no exceptions */ public String getPhoneNum() { return this.phoneNum; }//getPhoneNum() //+-----------+-------------------------------------------------------- //| Modifiers | //+-----------+ /** *Purpose: change the value of street * Parameter:string * Pre: none * Post:The value of the street is changed to the parameter * Return: nothing * errors: Throws no exceptions */ public void setStreet(String streetName) { this.street = streetName; }//setStreet() /** *Purpose: to change the value of the state * Parameter: string * Pre: none * Post:The value of the state is changed to the parameter * Return: nothing * errors: Throws no exceptions */ public void setState(String stateName) { this.state = stateName; }//setState() /** *Purpose:To change the value of the country * Parameter: string * Pre: none * Post:The value of the country is changed to the parameter * Return: nothing * errors: Throws no exceptions */ public void setCountry(String countryName) { this.country = countryName; }//setCountry() /** *Purpose: To change the value of the city * Parameter: string * Pre: none * Post:The value of the city is changed to the parameter * Return: nothing * errors: Throws no exceptions */ public void setCity(String cityName) { this.city = cityName; }//setCity() /** *Purpose: To change the value of the zipcode. * Parameter: string * Pre:none * Post:The value of the zipcode is changed to the parameter * Return: nothing * errors: Throws no exceptions */ public void setZip(String postCode) { this.zip = postCode; }//setZip() /*Purpose: To change the value of the phonenumber. * Parameter: string * Pre:none * Post:The value of the phonenumber is changed to the parameter * Return: nothing * errors: Throws no exceptions */ public void setPhoneNum(String foneNum) { this.phoneNum = foneNum; }//setPhoneNum() //+--------------+-------------------------------------------------- //| Capabilities | //+--------------+ /** * Purpose: Convert The Contents Of The Object To A Displayable String. * The product of this method can be passed as a parameter to one of the * constructors to rebuild the object. * Paramter: None. * Pre: All The Fields Of The Objects Are Initialized. * Post: No Value Is Changed. * Return: A String Containing All Values Of Fields Of This Object. * Throws No Exceptions. */ public String toString() { return this.street + "," + this.city + "," + this.state +"," + this.country + "," + this.zip + "," + this.phoneNum; }//toString() }//class StreetAddress