Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design, Implement, and Test a Visual Basic application that uses a hierarchy of

ID: 3636068 • Letter: D

Question

Design, Implement, and Test a Visual Basic application that uses a hierarchy of 3 classes related thru inheritance to represent Persons (the base class), Customers (derived from the Person class), and Preferred Customers (derived from the Customer class). The specifications of each class and the application follow.

The Person Class

Begin a new project and design a class named Person with the following properties.

LastName (string)
FirstName (string)
Address (string)
City (string)
State (string)
Zip (string)
Phone (string)
Implement the properties as public property procedures. Create and test a form to store data in each property of a Person object.

The Customer Class

Design a new class named Customer that is derived from the Person class. The Customer class should have the following properties.

CustomerNumber (integer)
MailingList (Boolean)
Comments (string)
The CustomerNumber property will be used to hold a unique number for each customer. The MailingList property will be set to True if the customer wishes to be on a mailing list, or False if he does not. The Comments property holds miscellaneous comments about the customer.

Modify the form to allow storing data in each property of a Customer object. To enter the customer comments, use a TextBox control with its Multiline and WordWrap properties set to True.

The PreferredCustomer Class

Design a new class named PreferredCustomer that is derived from the Customer class. The PreferredCustomer class should have the following properties.

PurchasesAmount (decimal)
DiscountLevel (single)
The PurchasesAmount property will be used to hold the customer’s cumulative purchases. The DiscountLevel property is determined by the PurchasesAmount property as follows.

When a preferred customer spends $500, he or she gets a 5% DiscountLevel on all future purchases.
When a preferred customer spends $1000, he or she gets a 6% DiscountLevel on all future purchases.
When a preferred customer spends $1500, he or she gets a 7% DiscountLevel on all future purchases.
When a preferred customer spends $2000 or more, he or she gets a 10% DiscountLevel on all future purchases.
Modify the application’s form to allow storing data in each property of a PreferredCustomer object. Add the object to a collection, using the customer number as a key. Allow the user to look up a preferred customer by the customer number, edit the customer data, and remove a customer from the collection.

Explanation / Answer

Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Data.Common Imports System.Diagnostics Imports System.Drawing Imports System.Data.SqlClient Imports System.Windows.Forms ' This form demonstrates using a BindingSource to bind ' a list to a DataGridView control. The list does not ' raise change notifications, however the DemoCustomer type ' in the list does. Public Class Form1 Inherits System.Windows.Forms.Form ' This button causes the value of a list element to be changed. Private changeItemBtn As New Button() ' This DataGridView control displays the contents of the list. Private customersDataGridView As New DataGridView() ' This BindingSource binds the list to the DataGridView control. Private customersBindingSource As New BindingSource() Public Sub New() ' Set up the "Change Item" button. Me.changeItemBtn.Text = "Change Item" Me.changeItemBtn.Dock = DockStyle.Bottom AddHandler Me.changeItemBtn.Click, AddressOf changeItemBtn_Click Me.Controls.Add(Me.changeItemBtn) ' Set up the DataGridView. customersDataGridView.Dock = DockStyle.Top Me.Controls.Add(customersDataGridView) Me.Size = New Size(800, 200) AddHandler Me.Load, AddressOf Form1_Load End Sub 'New Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Me.Load ' Create and populate the list of DemoCustomer objects ' which will supply data to the DataGridView. Dim customerList As New BindingList(Of DemoCustomer) customerList.Add(DemoCustomer.CreateNewCustomer()) customerList.Add(DemoCustomer.CreateNewCustomer()) customerList.Add(DemoCustomer.CreateNewCustomer()) ' Bind the list to the BindingSource. Me.customersBindingSource.DataSource = customerList ' Attach the BindingSource to the DataGridView. Me.customersDataGridView.DataSource = Me.customersBindingSource End Sub 'Form1_Load ' This event handler changes the value of the CompanyName ' property for the first item in the list. Private Sub changeItemBtn_Click(ByVal sender As Object, ByVal e As EventArgs) ' Get a reference to the list from the BindingSource. Dim customerList As BindingList(Of DemoCustomer) = _ CType(customersBindingSource.DataSource, BindingList(Of DemoCustomer)) ' Change the value of the CompanyName property for the ' first item in the list. customerList(0).CustomerName = "Tailspin Toys" End Sub _ Shared Sub Main() Application.EnableVisualStyles() Application.Run(New Form1()) End Sub End Class ' This class implements a simple customer type ' that implements the IPropertyChange interface. Public Class DemoCustomer Implements INotifyPropertyChanged ' These fields hold the values for the public properties. Private idValue As Guid = Guid.NewGuid() Private customerNameValue As String = String.Empty Private phoneNumberValue As String = String.Empty Public Event PropertyChanged As PropertyChangedEventHandler _ Implements INotifyPropertyChanged.PropertyChanged Private Sub NotifyPropertyChanged(ByVal info As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info)) End Sub ' The constructor is private to enforce the factory pattern. Private Sub New() customerNameValue = "Customer" phoneNumberValue = "(555)555-5555" End Sub ' This is the public factory method. Public Shared Function CreateNewCustomer() As DemoCustomer Return New DemoCustomer() End Function ' This property represents an ID, suitable ' for use as a primary key in a database. Public ReadOnly Property ID() As Guid Get Return Me.idValue End Get End Property Public Property CustomerName() As String Get Return Me.customerNameValue End Get Set(ByVal value As String) If Not (value = customerNameValue) Then Me.customerNameValue = value NotifyPropertyChanged("CustomerName") End If End Set End Property Public Property PhoneNumber() As String Get Return Me.phoneNumberValue End Get Set(ByVal value As String) If Not (value = phoneNumberValue) Then Me.phoneNumberValue = value NotifyPropertyChanged("PhoneNumber") End If End Set End Property End Class
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote