Question
Address Class Application Using Python Implement the class Address. An address object has a house number, a street, an optional apartment number, a city, a
Address Class Application
Using Python Implement the class Address. An address object has a house number, a street, an optional apartment number, a city, a state, and a postal code. Define the constructor such that an object can be created in one of two ways: with an apartment number or without. Supply a print method that prints the address with the street on one line and the city, state, and postal code on the next line. Supply the method def comesBefore(self, other) that tests whether an address comes before another when compared by postal code. Finally, supply the def getCountry(self) method that indicates the country in which the address is located.
Note: To complete this assignment, you will need to use the addressdemo.py file located in Project 11 folder on Blackboard. You will not be allowed to make any changes to addressdemo.py. All addresses are assumed to be in the USA by default.
addressdemo.py from address import Address # Construct two objects. a = Address(2500, "University Drive", "Turlock", "CA", "95382") b = Address(1200, "College Blvd", "Merced", "CA", "95340", "Apt 12") # Demonstrate the print method. print("1st address:") a.print() print() print("2nd address:") b.print() print() # Demonstrate the comesBefore method. a.comesBefore(b) # Demonstrate that all addresses are in the USA. print("1st address is in the", a.getCountry()) print("2nd address is in the", b.getCountry())
-------------------------------------------------------------------------------------------
SAMPLE RUN
1st address:
2500 University Drive
Turlock, CA 95382
2nd address:
Apt 12 - 1200 College Blvd
Merced, CA 95340
2nd address comes before 1st address
1st address is in the USA
2nd address is in the USA
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started