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...
/*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...
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...
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...
python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...
python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following A number of instance variables/fields to store a table of data. You can design them by your own. A constructor that creates a table with the following: a list of data. ip address a integer to indicate the number of elements in the sum_list/freq_list/average_list A get_ip_address() method that returns the ip address For example, consider the following code fragment: ip_key = '192.168.0.24' data_list =[(0,...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following A number of instance variables/fields to store a table of data. You can design them on your own. A constructor that creates a table with the following: a list of data. IP address an integer to indicate the number of elements in the sum_list/freq_list/average_list A get_ip_address() method that returns the IP address For example, consider the following code fragment: ip_key = '192.168.0.24' data_list =[(0,...
PLEASE WRITE THIS IN C++ Write a ComplexNumber class that has two member variables realNum and...
PLEASE WRITE THIS IN C++ Write a ComplexNumber class that has two member variables realNum and complexNum of type double. Your class shall have following member functions Complex(); Complex(double, double); Complex add(Complex num1, Complex num2); Complex subtract(Complex num1, Complex num2); string printComplexNumber(); Write a driver program to test your code. Please make sure your code is separated into Complex.h Containing definition of the class Complex.cpp Containing the implementation ComplexTestProgram.cpp Containing main program Use the following directive in class definition to...
Write a Python class to represent a LibraryMember that takes books from a library. A member...
Write a Python class to represent a LibraryMember that takes books from a library. A member has four private attributes, a name, an id, a fine amount, and the number of books borrowed. Your program should have two functions to add to the number of books and reduce the number of books with a member. Both functions, to add and return books, must return the final number of books in hand. Your program should print an error message whenever the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT