In: Computer Science
write the code in python
Design a class named PersonData with the following member variables:
Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData , which is derived from the PersonData class. The CustomerData class should have the following member variables:
The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool . It will be set to true if the customer wishes to be on a mailing list, or false if the customer does not wish to be on a mail-ing list. Write appropriate accessor and mutator functions for these member variables.
Next write a program which demonstrates an object of the CustomerData class in a program. Your program MUST use exception handling. You can choose how to implement the exception handling. Organize your non object oriented code into a main function
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
Let me know for any help with any other questions.
Thank You!
===========================================================================
class PersonData():
def __init__(self, lastName, firstName, address, city, state, zip, phone):
self.__last_name = lastName
self.__first_name = firstName
self.__address = address
self.__city = city
self.__state = state
self.__zip_code = zip
self.__phone = phone
def get_last_name(self): return self.__last_name
def get_first_name(self): return self.__first_name
def get_address(self): return self.__address
def get_city(self): return self.__city
def get_state(self): return self.__state
def get_zip(self): return self.__zip_code
def get_phone(self): return self.__phone
def set_first_name(self, fname): self.__first_name = fname
def set_last_name(self, lname): self.__last_name = lname
def set_address(self, address): self.__address = address
def set_city(self, city): self.__city = city
def set_state(self, state): self.__state = state
def set_zip(self, code): self.__zip_code = code
def set_phone(self, phone): self.__phone = phone
class CustomerData(PersonData):
customers = []
def __init__(self, lastName, firstName, address, city, state, zip, phone, customerNum, mailingList):
super().__init__(lastName, firstName, address, city, state, zip, phone)
if customerNum in CustomerData.customers:
raise ValueError('Duplicate Customer with the same ID already exist.')
self.__customer_number = customerNum
self.__mailing_list = mailingList
CustomerData.customers.append(customerNum)
def get_customer_number(self):
return self.__customer_number
def get_mailing_list(self):
return self.__mailing_list
def set_customer_number(self, customerNum):
if customerNum in CustomerData.customers:
raise ValueError('Duplicate Customer with the same ID already exist.')
self.__customer_number = customerNum
def set_mailing_list(self, mail):
self.__mailing_list = mail
def main():
john = CustomerData('Smith', 'John', '123 Main St', 'New York', 'New York', 12345, '123-456-7890', 123, True)
try:
# peter also has the same customer id as john which is 123
peter = CustomerData('Gomez', 'Peter', '345 Main St', 'New York', 'New York', 12345, '123-456-7890', 123, True)
except ValueError as e:
print(e)
print('Details of a Customer')
print('Full Name:',john.get_first_name(),john.get_last_name())
print('Address:',john.get_address(),'City:',john.get_city())
print('State:',john.get_state(),'Zip code:',john.get_zip())
print('Contact Number:',john.get_phone())
main()
========================================================================


