Define a class named Customer that holds private fields for a customer ID number, last name, first name, and credit limit. Include four public functions that each set one of the four fields. Do not allow any credit limit over $10,000. Include a public function that displays a Customer’s data.a. Write a main()function in which you declare a Customer, set the Customer’s fields, and display the results.b. Write a main()function that declares an array of five Customer objects. Prompt the user for values for each Customer, and display all five Customer objects
Question
Define a class named Customer that holds private fields for a customer ID number, last name, first name, and credit limit. Include four public functions that each set one of the four fields. Do not allow any credit limit over $10,000. Include a public function that displays a Customer’s data.a. Write a main()function in which you declare a Customer, set the Customer’s fields, and display the results.b. Write a main()function that declares an array of five Customer objects. Prompt the user for values for each Customer, and display all five Customer objects
Solution 1
Here is a Python solution for your problem:
class Customer:
def __init__(self):
self.__id = None
self.__last_name = None
self.__first_name = None
self.__credit_limit = None
def set_id(self, id):
self.__id = id
def set_last_name(self, last_name):
self.__last_name = last_name
def set_first_name(self, first_name):
self.__first_name = first_name
def set_credit_limit(self, credit_limit):
if credit_limit > 10000:
print("Credit limit cannot exceed $10,000")
else:
self.__credit_limit = credit_limit
def display(self):
print(f"Customer ID: {self.__id}, Last Name: {self.__last_name}, First Name: {self.__first_name}, Credit Limit: {self.__credit_limit}")
# a. Write a main()function in which you declare a Customer, set the Customer’s fields, and display the results.
def main():
customer = Customer()
customer.set_id(1)
customer.set_last_name("Doe")
customer.set_first_name("John")
customer.set_credit_limit(5000)
customer.display()
main()
# b. Write a main()function that declares an array of five Customer objects. Prompt the user for values for each Customer, and display all five Customer objects
def main():
customers = [Customer() for _ in range(5)]
for i in range(5):
id = int(input("Enter customer id: "))
last_name = input("Enter last name: ")
first_name = input("Enter first name: ")
credit_limit = int(input("Enter credit limit: "))
customers[i].set_id(id)
customers[i].set_last_name(last_name)
customers[i].set_first_name(first_name)
customers[i].set_credit_limit(credit_limit)
for customer in customers:
customer.display()
main()
This code first defines a Customer class with private fields for customer ID, last name, first name, and credit limit. It also includes public functions to set these fields, with a check to ensure the credit limit does not exceed $10,000. The display function is used to print the customer's details.
The main function creates a Customer object, sets its fields, and displays the results. The second main function creates an array of five Customer objects, prompts the user for values for each customer, and displays all five customer objects.
Solution 2
Here is the Python code for your request:
class Customer:
def __init__(self):
self.__id = None
self.__last_name = None
self.__first_name = None
self.__credit_limit = None
def set_id(self, id):
self.__id = id
def set_last_name(self, last_name):
self.__last_name = last_name
def set_first_name(self, first_name):
self.__first_name = first_name
def set_credit_limit(self, credit_limit):
if credit_limit > 10000:
print("Credit limit cannot exceed $10,000.")
else:
self.__credit_limit = credit_limit
def display(self):
print(f"Customer ID: {self.__id}, Last Name: {self.__last_name}, First Name: {self.__first_name}, Credit Limit: {self.__credit_limit}")
# a. Write a main()function in which you declare a Customer, set the Customer’s fields, and display the results.
def main():
customer = Customer()
customer.set_id(1)
customer.set_last_name("Doe")
customer.set_first_name("John")
customer.set_credit_limit(5000)
customer.display()
main()
# b. Write a main()function that declares an array of five Customer objects. Prompt the user for values for each Customer, and display all five Customer objects
def main():
customers = [Customer() for _ in range(5)]
for i in range(5):
id = int(input("Enter customer ID: "))
last_name = input("Enter last name: ")
first_name = input("Enter first name: ")
credit_limit = int(input("Enter credit limit: "))
customers[i].set_id(id)
customers[i].set_last_name(last_name)
customers[i].set_first_name(first_name)
customers[i].set_credit_limit(credit_limit)
for customer in customers:
customer.display()
main()
This code first defines a class `Customer
Similar Questions
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
Write a Java program to manage billing information for customers. The program should allow the user to input details for multiple customers and bills. For each customer, the program should prompt the user to enter a customer ID and name. For each bill, the program should prompt the user to enter a bill number, amount, date, and the corresponding customer ID. Once the user has input all the necessary information, the program should allow the user to search for bills by customer ID. Upon entering a customer ID, the program should display all bill amounts, dates, and numbers associated with that customer ID. Frame the program using classes for Customer and Bill, and implement methods to retrieve customer and bill details. Sample Input 3 // Number of Customers 1 // Customer IDJai // Customer Name 2Sakthi 3John 5 // Number of Bills 11 // Bill Number45663 // Bill Amount02/12/2023 // Bill Date2 // Customer ID 4489609/12/20232 77896509/04/20231 99675404/11/20221 33876511/11/202332 Sample Output 1145663.002/12/202344896.009/12/2023
Write a program to create a bank customer information using array of structures, nested structures and functions.First structure should hold the following information: Customer personal details: Name, Gender, Account Number, DOB; Second structure should hold the following information: Customer account details: Type of account, opening balance, closing balance
Write a java program to create a bank account with Name of the account holder, type of account(savings or current), Account number and Balance amount in the account. Also, create 5 customers for the class Bank_account using array of objects. Access the customers to perform credit, debit and display of balance.Input 1:Enter the customers:ReenaSavings1231000RobinCurrent4562000PraveenSavings7893000SherinCurrent2342500DeenaSavings5672000Enter choice:1. Credit2. Debit
Complete the function get_bank_data(). The function reads tot_customers and an array to store customer details(cust_id, cust_acc_num, cust_name, amount_in_account) in a struture for each customer at runtime. Read the customer details at runtime and store it in the array and return the array . The structure to store cust_id,cust_acc_num,cust_name,amount_in_account is predefined, refer it for your task completion.Input Format:Accept the count of total customers - which is provided inside main()Read customer id, customer account number , customer name and amount in account as line separatedand repeat it for total count of customers.Output Format:Returning the the read input from the function to main i
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.