Question

In: Computer Science

write the code in python Design a class named PersonData with the following member variables: lastName...

write the code in python

Design a class named PersonData with the following member variables:

  • lastName
  • firstName
  • address
  • city
  • state
  • zip
  • phone

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:

  • customerNumber
  • mailingList

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

Solutions

Expert Solution

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()

========================================================================


Related Solutions

C++ PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName...
C++ PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName firstName address city state zip phone 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: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool. It will...
Car Class Write a class named Car that has the following member variables: • year. An...
Car Class Write a class named Car that has the following member variables: • year. An int that holds the car’s model year. • make. A string object that holds the make of the car. • speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. • Constructor. The constructor should accept the car’s year and make as arguments and assign these values to the object’s year and make member variables....
/*Design and code a class Calculator that has the following * tow integer member variables, num1...
/*Design and code a class Calculator that has the following * tow integer member variables, num1 and num2. * - a method to display the sum of the two integers * - a method to display the product * - a method to display the difference * - a method to display the quotient * - a method to display the modulo (num1%num2) * - a method toString() to return num1 and num2 in a string * - Test your...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
Python Please (The Fan class) Design a class named Fan to represent a fan. The class...
Python Please (The Fan class) Design a class named Fan to represent a fan. The class contains: ■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ■ A private int data field named speed that specifies the speed of the fan. ■ A private bool data field named on that specifies whether the fan is on (the default is False). ■ A private float data field named radius that...
* Python * * Python Programming * Part 1: Product Class Write a class named Product...
* Python * * Python Programming * Part 1: Product Class Write a class named Product that holds data about an item in a retail store.   The class should store the following data in attributes: product id, item description, units in inventory, and price. Write the __init__ method to require all four attributes. Also write a __str__ method for debugging output.    Once you have written the class, write a main() function that creates three Product objects and stores the following...
Java Write a Payroll class as demonstrated in the following UML diagram. Member variables of the...
Java Write a Payroll class as demonstrated in the following UML diagram. Member variables of the class are: NUM_EMPLOYEES: a constant integer variable to hold the number of employees. employeeId. An array of integers to hold employee identification numbers. hours. An array of integers to hold the number of hours worked by each employee payRate. An array of doubles to hold each employee’s hourly pay rate wages. An array of seven doubles to hold each employee’s gross wages The class...
Write a Circle class that has the following member variables: radius as a double PI as...
Write a Circle class that has the following member variables: radius as a double PI as a double initialized with 3.14159 The class should have the following member functions: Default constructor Sets the radius as 0.0 and pi as 3.14159 Constructor Accepts the radius of the circles as an argument setRadius A mutator getRadius An accessor getArea Returns the area of the circle getDiameter Returns the diameter of the circle getCircumference Returns the circumference of the circle Write a program...
Write a Circle class that has the following member variables: • radius: a double • pi:...
Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the circle, which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT