RIS214
Class Test 4
You should always employ defensive programming to prevent run-time errors.
Ensure that your name and student number is in a comment block at the top of every class.
Your assignment will not be marked and you will get an incomplete if you do not do this.
Every part of your assignment will be marked as follows:
mark = copied ? -5 : runs ? 2 : good attempt ? 1 : 0;
if (Sum(marks) < 0)
{
assignment is incomplete
resubmit entire assignment
if (mark for resubmit > 50%)
mark = 0
else
assignment is incomplete
if (second assignment incomplete)
{
module is incomplete
Come back next year
}
}
Please read the departmental disciplinary code on the csi server. If you are found guilty of
plagiarism (dealer or stealer), you will get incomplete for this assignment and you will have to
resubmit. If your resubmitted program does not run correctly you will get an incomplete for
the module. Come back next year.
Remember that these weekly exercises are exercises. The more time you spend, the easier you
will find the tests and exam.
Submit before Wednesday 6 March 17:00.
Consider the scenario of an ATM.
Start with a new Windows forms application.
1. Add a struct to capture the details of a single Transaction. Make provision for the date
(DateTime) and amount (decimal) of a transaction. It should not be possible to change the date
or amount after a transaction was created.
2. Prepare an interface, IStatement, which will contain a single method, DrawStatement. The
method must take two DateTime parameters – one for the start date of a statement and one
for the end date of the statement. The method should return a generic list of Transaction
elements.
3. Add a class, CAccount.
3.1 The class should inherit from IStatement.
3.2 The class should have a private string data member for the account number.
3.3 The class should have a protected data member, Transactions, for all transactions (generic list
of Transaction).
3.4 The class should have a property to return the Balance of the account. The balance must be
calculated as the sum of amounts of all transactions.
3.5 The class should have only one constructor that takes the account number, opening date and
opening amount as parameters. The constructor should add an initial transaction with these
parameters to the list of transactions.
3.6 Implement the DrawStatement method to provide a list of all transactions between the given
dates.
3.7 Implement a method, DoDeposit, which will take a DateTime and decimal parameter and add a
transaction to the list of transactions with these details.
3.8 Declare an abstract method, DoWithdrawal. The method should also take a DateTime and
decimal parameter for the date and the amount of the transaction.
3.9 Override the object.ToString() method to return the account number.
4. Add a class CSavings, which will inherit from CAccount.
4.1 The class should have a single constructor that inherits from the constructor in CAccount.
4.2 Override the DoWithdrawal method from CAccount. Add a transaction with a negative amount
in the list of transactions. Implement the business rule that a withdrawal cannot be made if the
transaction will result in a negative balance.
5. Add a class CCreditCard which will inherit from CAccount.
5.1 Provide a private data member for the credit limit.
5.2 The class should have a single constructor that inherits from the constructor in CAccount.
Besides the parameters for account number, opening date and opening amount, the
constructor should have an extra parameter for the credit limit. Assign this value to the private
data member for the credit limit.
6.3 Declare a delegate for an event handler that will be executed when the credit card goes over its
limit.
5.4 Declare an event, OnLimitExceeded, of the above delegate.
5.5 Override the DoWithdrawal method from CAccount. Add a transaction with a negative amount
in the list of transactions. Implement the business rule that a withdrawal cannot be made if the
transaction will result in a balance that will exceed the limit. Raise the OnLimitExceeded event
if the transaction is illegal.
6. Use the Visual Studio tool and develop a class diagram.
7. Design the form as in the screen print. Give appropriate names to all controls. The Deposit,
Draw, Balance and Statement buttons must initially be disabled.
Rich text box for
account statements
8. Declare two objects in the form class, one for a savings account and one for a credit card
account.
9. Write the code for the Create Account button. Instantiate the savings account or the credit
card object depending on the radio button that is selected. You can hard code the values
“Savings” and “Credit card” for the account number.
Hint: You might save yourself time if you develop a method, GetAmount, to get an amount
from the user.
Enable the Deposit, Draw, Balance and Statement buttons once the account is created. Disable
the Create account button because for this application there will be only one savings account
and one credit card account. Swap the enabled properties if the user checks the other radio
button and the appropriate account has not yet been created.
10. Write the code for the Deposit button. Call the GetAmount method again but with a different
prompt. Remember that the selected radio button will determine for which account the
DoDeposit method will be called. Use polymorphism to make it easier. Use the ToString()
method to get the caption in the message box.
11. Write the code for the Draw button. Use polymorphism again.
12. Write the code for the Balance button to display a message box that will call the Balance
property of the appropriate account. Use the ToString() method to get the caption in the
message box.
13. Write the code for the Statement button. The button should ask the start date and end date
and then display the transactions between these dates in the richtextbox control. Set the font
of the richtextbox to Consolas (a non-proportional font) and ensure that the output is neatly
aligned. Use the ToString() method to get the first line of output as in the example below.
Develop a method to obtain the dates from the user. Develop your own input box that will
display a DateTimePicker as in the screen print.