Write a class that represents a person’s mailing address. It should have separate fields forthe name, street address, city, state and ZIP code. Write an application AddressBook, toincorporate address book application :-(a) To add addresses.(b) Print addresses.
Question
Write a class that represents a person’s mailing address. It should have separate fields forthe name, street address, city, state and ZIP code. Write an application AddressBook, toincorporate address book application :-(a) To add addresses.(b) Print addresses.
Solution
Sure! Here is a step-by-step guide to writing a class that represents a person's mailing address:
Step 1: Define the class Start by defining a class called "Address" that will represent a person's mailing address.
Step 2: Define the class fields Inside the Address class, define separate fields for the name, street address, city, state, and ZIP code. These fields will store the respective information for each address.
Step 3: Implement the constructor Create a constructor for the Address class that takes parameters for each field and initializes them.
Step 4: Implement getter and setter methods To access and modify the address fields, implement getter and setter methods for each field. These methods will allow you to retrieve and update the address information.
Step 5: Write the AddressBook application Create a separate class called "AddressBook" that will serve as the application to manage the addresses. Inside this class, you can implement methods to add addresses and print addresses.
Step 6: Implement the addAddress method In the AddressBook class, create a method called "addAddress" that takes parameters for each field of the Address class. Inside this method, create a new instance of the Address class using the provided information and add it to a list or any other data structure to store multiple addresses.
Step 7: Implement the printAddresses method In the AddressBook class, create a method called "printAddresses" that will iterate over the list of addresses and print each address's information.
That's it! You have now written a class that represents a person's mailing address and an AddressBook application to manage addresses.
Similar Questions
Create 3 variables to store street, city and country, now create address variable to store entire address. Use two ways of creating this variable, one using + operator and the other using f-string. Now Print the address in such a way that the street, city and country prints in a separate line
Create two classes. The first holds customer data—specifically, a customer number and zip code. The second, a class for cities, holds the city name, state, and zip code. Additionally, each class contains a constructor that takes parameters to set the field values. Create a friend function that displays a customer number and the customer’s city, state, and zip code.Write a brief main() function to prompt the user to input customer and city information, create objects of the respective classes based on user input, and then call the friend function to display the customer information along with the associated city, state, and zip code. While calling Friend function output the statement “Calling friend function”Ensure the user provides the following details:Customer numberCity nameStateZip code
Match each concept to the correct description. Question 21 options: This follows the salutation and states the theme of the letter (leave a line open) This is written out After this, you add your print name and designation This is usually 'Yours faithfully' (only use 'Yours sincerely' if you know the reader well) For this, use the name of recipient if known; otherwise write "Dear Sir/Madam/Client/Customer" On the same line as date Leave a line after the postal code This is in the letterhead This follows the reference Leave a line open after each paragraph 1. Name of the company 2. Reference 3. Date 4. For attention 5. Recipient's name and address. 6. Salutation 7. Subject line/heading 8. Paragraphs 9. Complimentary close 10. Sender's signature
Dictionary Creation: a. Create a dictionary named contacts with keys 'Alice' and 'Bob' mapped to their respective email addresses.Dictionary Operations: a. Retrieve the email address of 'Alice' from the dictionary contacts. b. Add a new key-value pair to contacts with 'Eric' mapped to '[email protected]'. c. Delete the entry for 'Alice' from the dictionary contacts.
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone_number, and e-mail address. A student has a status (freshman, sophomore, junior, or senior). An employee has an office, salary. A faculty member has office_hours and a rank. A staff member has a title. Override the toString() method in each of these classes to display their details. Write a Java application and subsequent pseudocode to implement/simulate the same.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.