CA4 Object Oriented Programming C#

CA 4 Due  Friday 24 April 2020  C#

1. Write a class to represent a Customer.

The Customer class should have the following three attributes:

    A unique Customer ID number (int).
    Name (string)
    Account Balance (double)

    Use properties to enable access to the attributes.
    Provide getter and setter methods for each attribute.
    You can use the shortcut notation for properties {get;set;}.

The class should have 2 constructors:

(i)    A default constructor which sets a unique value for the Customer ID number. The Account Balance should be set to 0.

(ii)    A parameterised constructor, which should initialise the name and account balance. It should also set a unique value for the Customer number.

Provide a virtual method called AddCharge which takes an amount charged as a parameter and subtracts it from the account balance. The method should return true to indicate that the account has been charged.

Provide a ToString() method  to return the following values as a string:

ID Number          Name         Money owed       

In the main program:

(i)    Declare and create a customer object, customer1.
(ii)    Set the name to Mandy.
(iii)    Write the details to the console.
(iv)    Declare and create a customer object, customer2 with the name Jimmy using the parameterised constructor.
(v)    Add a charge of 500.
(vi)    Write the details to the console.

2.  Inheritance

Create a class for a TrialCustomer that inherits the features of the Customer class and also has the attribute:

Maximum Credit Available (double).

Constructors
The class should have 2 constructors:
(i)    A default constructor, calling the parent class default constructor. The Maximum Credit Available should be set to 0.
(ii)    A parameterised constructor to set Name, and Maximum Credit Available. The name should be passed back to the parent class constructor.

Methods

(i)    Provide an override  method for AddCharge which takes an amount charged as a parameter.
(ii)    If there is sufficient credit available,it subtracts the amount from the account balance. The method should return true if successful, false if insufficient credit.
(creditAvailable =AccountBalance+MaximumCreditAllowed)

(ii) Provide a ToString() method  to return the following values as a string:

ID Number          Name         Money owed        Credit allowed.   

4. Testing your Class in the Main Program – you can add to the existing main.

(i)    Declare and create a TrialCustomer object, trialCustomer1.
(ii)    Set the Name to Anastasia.
(iii)    Set the Maximum Credit Allowed to 1000.
(iv)    Write the details to the console.
(v)    Add a charge of 500
(vi)    Write the details to the console.

(vii)    Declare and create a TrialCustomer object, TrialCustomer2 with the name Maximilian and a Maximum Credit of 500, using the parameterised constructor.
(viii)    Write the details to the console.
(ix)    Add a charge of 700 and check if allowed.
(x)    Write the details to the console.

(xi)    Create an array of 5 Customer objects.
(xii)    Read in details from the provided file customers.txt
Each line has two or three fields:
name, account balance, max credit (if  a trial customer)
(xiii)    Create a Customer or TrialCustomer object from each line in the file. (hint: if 2 fields create a customer, if 3 create a trial customer).
(xiv)    Use a loop to print out the details of all the objects to the console.