1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include<iostream>
using namespace std;
class Address {
int houseNumber;
string street;
int apartmentNumber;
string city;
string state;
string zipCode; // e.g., "47405-1234"
Address(int houseNumber,
string street,
// no apartmentNumber
string city,
string state,
string zipCode) {
this.houseNumber = houseNumber;
this.street = street;
this.city = city;
this.state = state;
this.zipCode = zipCode;
}
Address(int houseNumber,
string street,
int apartmentNumber,
string city,
string state,
string zipCode) {
this(houseNumber, street, city, state, zipCode);
this.apartmentNumber = apartmentNumber;
}
void print() {
System.out.println("Street: " + street);
System.out.println("City: " + city
+ "State: " + state
+ "Postal Code: " + zipCode);
}
int compareTo(Address a) {
// same conventions as for Strings
return this.zipCode.compareTo(a.zipCode);
}
|