package edu.columbia.cs.cs1007.company;
/**
* The class Address implements a mailing address.
* @author Julia Stoyanovich (jds2109@columbia.edu)
* COMS 1007, Summer 2009
*
*
*/
public class Address {
// Instance variables
private String _street;
private String _number;
private String _city;
private String _state;
private String _zip;
private String _country;
/**
* Constructor method.
* @param street
* @param number
* @param city
* @param state
* @param zip
* @param country
*/
public Address(String street, String number, String city, String state, String zip, String country) {
_street = street;
_number = number;
_city = city;
_state = state;
_zip = zip;
_country = country;
}
/**
* Constructor method that assumes that the address is in US.
* @param street
* @param number
* @param city
* @param state
* @param zip
*/
public Address(String street, String number, String city, String state, String zip) {
this(street, number, city, state, zip, "USA");
}
/**
* Constructor method.
* @param that - another instance of the class Address.
*/
public Address(Address that) {
_street = that._street;
_number = that._number;
_city = that._city;
_state = that._state;
_zip = that._zip;
_country = that._country;
}
/**
* Move to a different street address within a city.
* @param street new street
* @param number new number
* @param zip new ZIP code
*/
public void move(String street, String number, String zip) {
_street = street;
_number = number;
_zip = zip;
}
/**
* Compare an instance of Address to another instance.
* @param other
* @return true if two instances have the same content, false otherwise.
*/
public boolean equals(Object other) {
Address that = (Address)other;
return _street.equals(that._street) && _number.equals(that._number) && _city.equals(that._city) &&
_state.equals(that._state) && _zip.equals(that._zip) && _country.equals(that._country);
}
/**
* Generate a string representation of the address.
* @return text description of an address.
*/
public String toString() {
String stringRepresentation = _number + " " + _street + ", " + _city + ", " + _state + " " + _zip + ", " + _country;
return stringRepresentation;
}
public static void main(String args[]) {
Address address1 = new Address("Amsterdam Avenue", "1214", "New York", "NY", "10027-7003", "USA");
Address address2 = address1;
Address address3 = new Address(address1);
System.out.println("Address 1: " + address1.toString());
System.out.println("Address 2: " + address2.toString());
System.out.println("Address 3: " + address3.toString());
address1.move("West 113 Street", "502", "10025");
System.out.println("Address 1: " + address1.toString());
System.out.println("Address 2: " + address2.toString());
System.out.println("Address 3: " + address3.toString());
}
}
|