Question: Hi, I'm having really hard time with this. Could someone solve the required parts in this??????? It's only a few parts that ask you to

Hi, I'm having really hard time with this.

Could someone solve the required parts in this???????

It's only a few parts that ask you to create code.

1 In this assignment, you will create a custom exception class named CreditLimitViolationException. You will also create a CreditCard class that uses the custom exception class as follows: When a pending charge results in a credit-limit violation, the charge is rejected and a CreditLimitViolationException is thrown back to the caller. Exercise 1: Create a credit-card class-library project. CreditCard Class Library Project

1. Create a new Library project called CreditCardLibrary. Add two new classes, CreditCard and CreditLimitViolationException (delete Class1.vb), to the project. Make sure that the access modifiers for the CreditCard and CreditLimitViolationException classes are public. The CreditLimitViolationException Class

2. Create the following exception class inheriting from System.ApplicationException. Public Class CreditLimitViolationException Inherits ApplicationException Public Sub New() End Sub Public Sub New(message As String) MyBase.New(message) End Sub Public Sub New(message As String, inner As Exception) MyBase.New(message, inner) End Sub End Class The CreditCard Class The CreditCard class has two decimal properties, Balance and CreditLimit, and two constructors to set the initial property values.

3. Add the Balance and CreditLimit properties to the CreditCard class.

4. Add two constructors to the CreditCard class, a default constructor and a parameterized constructor taking two parameters, balance and creditLimit. Set the initial values for the Balance and CreditLimit properties in the constructors.

Public Sub New() '*** Write code to set default property values here.

End Sub

Public Sub New(balance As Decimal, creditLimit As Decimal)

'*** Write code to set initial property values here. End Sub

5. Add the following two sub-procedures to the CreditCard class, writing the code to implement them: Public Sub Charge(amount As Decimal) '*** Write code to post a charge to the credit card. '*** If (current balance + amount) > credit limit, '*** throw a CreditLimitViolationException with the error message '*** "Charge exceeds credit limit." End Sub

Public Sub Payment(amount As Decimal) '*** Write code to post a payment to the credit card. End Sub

6. Build the library to make sure everything compiles.

Exercise 2: Write test code for the CreditCard class library.

1. Add a new Windows Forms project to your solution called CreditCardTester.

2. Set the CreditCardTester project as the startup project. 3. Create the following test form using acceptable names for controls and a natural tab order. Note that the Balance and CreditLimit textboxes have their ReadOnly properties set to true. 4. Add a reference to the CreditCardLibrary to the CreditCardTester project.

5. The command button labeled Clear should clear the Charge and Payment textboxes.

6. The button labeled Exit should exit the program. 7. Add the following code to initialize the CreditCard object in the forms code-behind; you may use any values you like for the initial credit-card balance and credit limit.

Imports CreditCardLibrary Public Class Form1 Private _creditCard As New CreditCard(5467.12, 10000)

8. In the Form_Load event, set the Text properties for the Credit Limit and Balance textboxes:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load txtCreditLimit.Text = _creditCard.CreditLimit.ToString("c") txtBalance.Text = _creditCard.Balance.ToString("c") End Sub

9. Enter the following code for the Click event of the first Post button, which posts charges to the

CreditCard object. Take the time to understand what this code does. Private Sub btnCharge_Click(sender As Object, e As EventArgs) Handles btnCharge.Click Try If IsNumeric(txtCharge.Text) Then _creditCard.Charge(CDec(txtCharge.Text)) txtBalance.Text = _creditCard.Balance.ToString("c") Else MessageBox.Show("Please enter numeric value for charge.", "Invalid Charge Amount") End If Catch ex As CreditLimitViolationException Dim emsg As String = String.Format("{0:c} charge exceeds credit limit.", CDec(txtCharge.Text)) MessageBox.Show(emsg, "Credit Limit Violation", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally txtCharge.Focus() End Try End Sub

10. Implement the Click event for the second Post button, which posts payments to the CreditCard object. 11. Save your application. This is the end of Exercise 2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!